├── project ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── hello │ │ ├── AppConfig.java │ │ ├── Application.java │ │ └── GreetingController.java ├── settings.gradle ├── .gitignore └── build.gradle ├── images ├── book.png ├── sshd.png ├── first_login.png ├── stage.view.png ├── create_admin.png ├── jenkins_ready.png ├── unlock_jenkins.png ├── cli_fix_tcp_port.png ├── install_plugins.png ├── pipeline.plugin.png ├── cli_ssh_public_key.jpg └── installing_plugins.png ├── jobs ├── publish2.groovy ├── demo1.groovy ├── publish.groovy └── build.groovy ├── .gitignore ├── slide_images ├── JenkinsPipeline.001.png ├── JenkinsPipeline.002.png ├── JenkinsPipeline.003.png ├── JenkinsPipeline.004.png ├── JenkinsPipeline.005.png ├── JenkinsPipeline.006.png ├── JenkinsPipeline.007.png ├── JenkinsPipeline.008.png ├── JenkinsPipeline.009.png ├── JenkinsPipeline.010.png ├── JenkinsPipeline.011.png ├── JenkinsPipeline.012.png ├── JenkinsPipeline.013.png ├── JenkinsPipeline.014.png ├── JenkinsPipeline.015.png ├── JenkinsPipeline.016.png └── JenkinsPipeline.017.png ├── README.md ├── DEMO.md ├── INSTALL.md ├── NOTE.md └── CLI.md /project/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'jenkins-sample-project' 2 | -------------------------------------------------------------------------------- /images/book.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/book.png -------------------------------------------------------------------------------- /images/sshd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/sshd.png -------------------------------------------------------------------------------- /images/first_login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/first_login.png -------------------------------------------------------------------------------- /images/stage.view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/stage.view.png -------------------------------------------------------------------------------- /images/create_admin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/create_admin.png -------------------------------------------------------------------------------- /images/jenkins_ready.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/jenkins_ready.png -------------------------------------------------------------------------------- /images/unlock_jenkins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/unlock_jenkins.png -------------------------------------------------------------------------------- /images/cli_fix_tcp_port.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/cli_fix_tcp_port.png -------------------------------------------------------------------------------- /images/install_plugins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/install_plugins.png -------------------------------------------------------------------------------- /images/pipeline.plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/pipeline.plugin.png -------------------------------------------------------------------------------- /jobs/publish2.groovy: -------------------------------------------------------------------------------- 1 | node { 2 | deployTo job: "build", war: "jenkins-sample-project.war", context: "Demo2" 3 | } 4 | -------------------------------------------------------------------------------- /images/cli_ssh_public_key.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/cli_ssh_public_key.jpg -------------------------------------------------------------------------------- /images/installing_plugins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/images/installing_plugins.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | temp 3 | jenkins-cli.jar 4 | jenkins_kata 5 | jenkins_kata.pub 6 | workflowLibs 7 | apache-tomcat-* 8 | .bak 9 | -------------------------------------------------------------------------------- /project/.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .gradle 3 | .project 4 | .settings 5 | bin 6 | build 7 | src/main/java/com/github/byogc4j/Main.java 8 | -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.001.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.002.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.003.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.004.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.004.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.005.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.006.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.006.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.007.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.008.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.008.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.009.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.010.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.010.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.011.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.011.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.012.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.012.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.013.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.013.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.014.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.014.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.015.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.015.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.016.png -------------------------------------------------------------------------------- /slide_images/JenkinsPipeline.017.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qrtt1/JCConf2016_JenkinsPipeline/HEAD/slide_images/JenkinsPipeline.017.png -------------------------------------------------------------------------------- /project/src/main/java/hello/AppConfig.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @ComponentScan 8 | public class AppConfig { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /jobs/demo1.groovy: -------------------------------------------------------------------------------- 1 | node { 2 | stage ('checkout') { 3 | echo 'checkout from git' 4 | } 5 | stage ('build') { 6 | echo 'build' 7 | } 8 | stage ('test') { 9 | echo 'test' 10 | } 11 | stage ('war') { 12 | echo 'war' 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JCConf 2016 2 | 3 | 投影片:https://speakerdeck.com/qrtt1/jcconf2016-jenkins-pipeline 4 | 5 | # Jenkins Pipeline KATA 6 | 7 | * [Jenkins 基本安裝與啟用](INSTALL.md) 8 | * [Jenkins Cli](CLI.md) 9 | * [Jenkins 講稿](NOTE.md) 10 | * [Jenkins Demo 準備](DEMO.md) 11 | 12 | # 其他資料 13 | 14 | gitter 討論提到的東西: 15 | 16 | * https://jenkins.io/blog/2016/09/19/blueocean-beta-declarative-pipeline-pipeline-editor/ 17 | 18 | -------------------------------------------------------------------------------- /jobs/publish.groovy: -------------------------------------------------------------------------------- 1 | node { 2 | def job = "build" 3 | def war = "jenkins-sample-project.war" 4 | def deployPath = "/Users/qrtt1/temp/JenkinsPipelineKata/apache-tomcat-8.5.6/webapps" 5 | stage ('Deploy') { 6 | sh "rm -f *.war" 7 | step ([$class: 'CopyArtifact', 8 | projectName: "$job", 9 | filter: '**/*.war', flatten: true]) 10 | 11 | sh "cp $war $deployPath/Demo##${BUILD_NUMBER}.war" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /project/src/main/java/hello/Application.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.support.SpringBootServletInitializer; 6 | 7 | @SpringBootApplication 8 | public class Application extends SpringBootServletInitializer { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(Application.class, args); 12 | } 13 | } -------------------------------------------------------------------------------- /project/src/main/java/hello/GreetingController.java: -------------------------------------------------------------------------------- 1 | package hello; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public class GreetingController { 11 | 12 | @RequestMapping("/hello") 13 | public Map hello() { 14 | HashMap body = new HashMap<>(); 15 | body.put("message", "hello 9527"); 16 | return body; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /jobs/build.groovy: -------------------------------------------------------------------------------- 1 | node { 2 | stage ('checkout') { 3 | echo 'checkout from git' 4 | git url: 'git@github.com:qrtt1/JCConf2016_JenkinsPipeline.git', branch: 'master' 5 | } 6 | 7 | dir ('project') { 8 | pwd() 9 | stage ('build') { 10 | sh """gradle clean build""" 11 | } 12 | stage ('test') { 13 | sh """gradle check""" 14 | } 15 | stage ('war') { 16 | sh """gradle war""" 17 | } 18 | stage ('archive') { 19 | step([$class: 'ArtifactArchiver', artifacts: "build/**/*.war", fingerprint: true]) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /project/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE") 7 | } 8 | } 9 | 10 | apply plugin: 'java' 11 | apply plugin: 'eclipse' 12 | apply plugin: 'idea' 13 | apply plugin: 'spring-boot' 14 | apply plugin: 'war' 15 | 16 | jar { 17 | baseName = 'jenkins-sample-project' 18 | version = '0.1.0' 19 | } 20 | 21 | repositories { 22 | jcenter() 23 | } 24 | 25 | sourceCompatibility = 1.8 26 | targetCompatibility = 1.8 27 | 28 | dependencies { 29 | compile("org.springframework.boot:spring-boot-starter-web") 30 | } 31 | -------------------------------------------------------------------------------- /DEMO.md: -------------------------------------------------------------------------------- 1 | ## Demo 2 | 3 | Demo 前置作業需先設定好 [jenkins-cli](CLI.md),並安裝需要的 Plugin。 4 | 5 | ## Plugin 安裝 6 | 7 | ### Plugin Id: copyartifact 8 | 9 | ``` 10 | java -jar jenkins-cli.jar -s http://127.0.0.1:1234/ -i jenkins_kata install-plugin copyartifact 11 | ``` 12 | 13 | ### Plugin Id: workflow-cps-global-lib 14 | 15 | 16 | *設定 SSHD* 17 | 18 | 使用 shared library 需要用 git repo,目前的 plugin 搭配 sshd 使用 19 | 20 | ![](images/sshd.png) 21 | 22 | ``` 23 | java -jar jenkins-cli.jar -s http://127.0.0.1:1234/ -i jenkins_kata install-plugin workflow-cps-global-lib 24 | ``` 25 | 26 | *設定 ssh config* 27 | 28 | 設定 ssh config 將 `git.jenkins.kata` 對應至 `127.0.0.1:1235`,將以使用者 `kata` 與對應的 private key 進行認證 29 | 30 | ``` 31 | Host git.jenkins.kata 32 | HostName 127.0.0.1 33 | Port 1235 34 | User kata 35 | IdentityFile ~/.ssh/jenkins_kata 36 | ``` 37 | 38 | 第 1 次 checkout 因為沒有內容,所以只會建空目錄: 39 | 40 | ``` 41 | qty:JenkinsPipelineKata qrtt1$ git clone ssh://git.jenkins.kata/workflowLibs.git 42 | Cloning into 'workflowLibs'... 43 | The authenticity of host '[127.0.0.1]:1235 ([127.0.0.1]:1235)' can't be established. 44 | RSA key fingerprint is 38:c6:24:fd:5a:df:92:f4:51:3f:92:ca:c3:a2:36:a7. 45 | Are you sure you want to continue connecting (yes/no)? yes 46 | Warning: Permanently added '[127.0.0.1]:1235' (RSA) to the list of known hosts. 47 | Checking connectivity... done. 48 | warning: remote HEAD refers to nonexistent ref, unable to checkout. 49 | ``` 50 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # Jenkins Pipeline KATA 2 | 3 | ## 安裝 4 | 5 | ### 取得 Jenkins 6 | 7 | 由 Jenkins 官網下載 WAR 檔。 8 | 9 | ### 啟動 Jenkins 10 | 11 | ``` 12 | JENKINS_HOME=./temp java -jar jenkins.war --httpPort=1234 13 | ``` 14 | 15 | * 預設 Jenkins 會使用 `$HOME/.jenkins` 的位置作為工作目錄,透過 ```JENKINS_HOME``` 能指定不同的目錄 16 | * 預設 Jenkins 會使用 `8080` port,使用 `--httpPort` 能指定不同的 port 17 | 18 | 19 | 在啟動的過程會看到: 20 | 21 | ``` 22 | ************************************************************* 23 | ************************************************************* 24 | ************************************************************* 25 | 26 | Jenkins initial setup is required. An admin user has been created and a password generated. 27 | Please use the following password to proceed to installation: 28 | 29 | 16816244bd2440728414eac7c13f317c 30 | 31 | This may also be found at: /Users/qrtt1/temp/JenkinsPipelineKata/downloads/temp/secrets/initialAdminPassword 32 | 33 | ************************************************************* 34 | ************************************************************* 35 | ************************************************************* 36 | ``` 37 | 38 | 在第 1 次啟動時,需輸入此隨機密碼: 39 | 40 | ![](images/unlock_jenkins.png) 41 | 42 | 43 | ### 安裝 Plugin 與設定帳號 44 | 45 | 通過驗證後,需選擇 plugin 的安裝。選擇 `Install suggested plugins` 繼續常用 Plugin 安裝: 46 | 47 | ![](images/install_plugins.png) 48 | 49 | 等待安裝完成: 50 | 51 | ![](images/installing_plugins.png) 52 | 53 | 看到 `Jenkins is ready` 時,就是完成安裝了: 54 | 55 | ![](images/jenkins_ready.png) 56 | 57 | 接著,它會要求你建立 Admin 帳號: 58 | 59 | ![](images/create_admin.png) 60 | 61 | 完成後,就能登入 Jenkins: 62 | 63 | ![](images/first_login.png) 64 | -------------------------------------------------------------------------------- /NOTE.md: -------------------------------------------------------------------------------- 1 | 2 | ## 引言 3 | 4 | ![](slide_images/JenkinsPipeline.001.png) 5 | 6 | 這次的「快講」挑了 Jenkins Pipeline 的主題來介紹。他算是 Jenkins 2.x 後主推的功能。 7 | 雖然他並不是在 2.x 之後才有的 Plugin。但依「官網」文件安排可以看出 Pipeline 是被 Highlight 出來的重點功能。 8 | 9 | ## 什麼是 Pipeline 10 | 11 | ### 關於 Pipeline 12 | 13 | ![](slide_images/JenkinsPipeline.002.png) 14 | 15 | 在 IT 領域,我們常會選擇一些隱喻的辭來描述工作現場的事件或術語,像是以雲端隱喻網路。 16 | 而 Pipeline 則是隱喻軟體開發「流程」,因為由開發產出的原始碼或設計師產出的成品,透過若干連續的步驟合成為最終的產品。如同工廠裡的流水線一般。 17 | 18 | 在這裡的 Pipeline 應該源於 [Continuous Delivery](https://www.amazon.com/Continuous-Delivery-Deployment-Automation-Addison-Wesley-ebook/dp/B003YMNVC0/ref=mt_kindle?_encoding=UTF8&me=) 書本上倡導的 Delivery Pipeline 的概念: 19 | 20 | ![](images/book.png) 21 | 22 | 在 Jenkins 2.x 後,將 Pipeline Plugin 列為預設會安裝的 Plugin(若是使用 Jenkins 1.x 仍可透過安裝 Pipeline Plugin 使用它),在這之前它並非被稱作 Pipeline。 23 | 只能推測因為 DevOps 興起後 Delivery Pipeline 概念的推廣,讓 Pipeline 的隱喻有較高的能見度。於是將 *Workflow* Plugin 改了名字,成為 [Pipeline Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin): 24 | 25 | ![](images/pipeline.plugin.png) 26 | 27 | 實際上它只有換了「名稱」但身份證字號並沒有換,Plugin ID (workflow-aggregator ) 依然保留著 workflow 的字樣,較晚開發的 Plugin 才漸漸捨棄 workflow 的字樣,開始以 pipeline 為名。 28 | 29 | ### 關於 Pipeline Job 30 | 31 | 具體來說,Jenkins Pipeline 實際只是 Job 的一種型式。所以在 Jenkins 內使用 Pipeline 就是建立 1 個 Pipeline Job,而 Pipeline 由多個 step 組成,step 即為實際上的執行邏輯。 32 | 33 | 另外得注意的是,Jenkins Pipeline 試圖支援 Pause/Resume 的功能,為了能讓 Pipeline Job 保存狀態,所以 pipeline 必需是可以序列化的,或是以 function 的型式透過 `@NonCPS` annotation 宣告此 function 不保留狀態(但這僅適用於能快速執行完的 function,不然 Jenkins 會試等待它結束)。 34 | 35 | 36 | ## 為什麼該用 Pipeline 37 | 38 | 在網官介紹 Pipeline 的部分這麼說: 39 | 40 | > Pipelines are Jenkins jobs enabled by the Pipeline (formerly called "workflow") plugin and built with simple text scripts that use a Pipeline DSL (domain-specific language) based on the Groovy programming language. 41 | 42 | ![](slide_images/JenkinsPipeline.003.png) 43 | 44 | 在過去我們能使用 FreeStyle Job 搭配各式各樣的工具,像是 Ant, Maven 或 Shell Script 建立單一的建置流程。無論內容單簡、複雜全都塞進一組 Job 內,若是需要定義 Job 間的協作,需透過 Web Console 設定觸發條件來。 45 | 46 | 現在 Pipeline Job 提供 Pipeline DSL 透過簡單的語法,讓你透過 Pipeline DSL 組織工作,並能在 Pipeline 區分工作階段且能透過 "step" 明確呼叫其他 Jenkins Job。在建置工作流程上的表現更加直覺,有著 FreeStyle Job 的自由度,也有 Pipeline as Code 的透明感,並且因為 Pipeline as Code 達成 Continuous Delivery 倡導的,事事都上版控,不放棄任何細節的追蹤管理。 47 | 48 | ## Pipeline DSL 49 | 50 | ![](slide_images/JenkinsPipeline.004.png) 51 | 52 | 因此,我們可以意識到,要上手 Jenkins Pipeline 的一個重點在於學習 Pipeline DSL。今天只有不到 15 分鐘的時間,這邊僅列出學習資源。等一下透過簡單的 demo 跟大家介紹一下 Pipeline DSL 長什麼樣子,該怎麼使用它。 53 | 54 | ## Pipeline Job 55 | 56 | ![](slide_images/JenkinsPipeline.005.png) 57 | 58 | 建立 Pipeline Job 的型式主要分為二種: 59 | 60 | * Pipeline 61 | 62 | 就是 1 個 Pipeline 對應 1 個 Job。它允許你直接透過 Web Console 在 Script Box 內直接寫 Pipeline DSL,不過這只推薦給初學者做實驗用,或是驗證一下新的 Pipeline 寫法是不是合用,因為這麼寫少了提交 Pipeline DSL 進版本控制系統的流程,在開發上比較快一些。另一種方式是透過版本控制系統拉回來的檔案使用,需要指定 repository 的位置與 Pipeline DSL 的路徑。 63 | 64 | * Multibranch Pipeline 65 | 66 | Multibranch Pipeline 就是讓你指定 1 個版本控制系統的 repository 與 1 個 Pipeline DSL 路徑,它會依 branch 建出所有的 Pipeline Job。這很適用在專案的不同狀態,例如在你 1 個 Web 專案建出 {product, staging, testing} 3 個 branch,它就會建出 3 個 Pipeline Job。 67 | 68 | ![](slide_images/JenkinsPipeline.006.png) 69 | ![](slide_images/JenkinsPipeline.007.png) 70 | 71 | ## Pipeline 規劃 72 | 73 | ![](slide_images/JenkinsPipeline.008.png) 74 | 75 | 這是個簡化版的 Pipeline Flow,在官網上有個較完整的[範例](https://jenkins.io/images/pipeline/realworld-pipeline-flow.png),後讀的 demo 我們會以灰色 block 部分為主。這每一個 block 換作 Jenkins Pipeline 的術語,則是 stage (階段),在每個階段有各自執行的指令,當 Pipeline DSL 遇到 `stage` 指令(step) 時,就會在 Stage View 建出一欄資料表示,這樣在哪個階段失敗都看得一清二楚: 76 | 77 | ![](images/stage.view.png) 78 | 79 | ## Demo 80 | 81 | 接下來會透過簡單的例子來展示 Pipeline Job 與 Pipeline DSL 的使用。 82 | 83 | ![](slide_images/JenkinsPipeline.009.png) 84 | 85 | ## Steps 86 | 87 | ![](slide_images/JenkinsPipeline.010.png) 88 | ![](slide_images/JenkinsPipeline.011.png) 89 | ![](slide_images/JenkinsPipeline.012.png) 90 | ![](slide_images/JenkinsPipeline.013.png) 91 | 92 | ## Refactoring 93 | 94 | ![](slide_images/JenkinsPipeline.014.png) 95 | 96 | ## Shared Library 97 | 98 | ![](slide_images/JenkinsPipeline.015.png) 99 | 100 | ## My opinion 101 | 102 | ![](slide_images/JenkinsPipeline.016.png) 103 | 104 | ## Any questions ? 105 | 106 | ![](slide_images/JenkinsPipeline.017.png) 107 | -------------------------------------------------------------------------------- /CLI.md: -------------------------------------------------------------------------------- 1 | 2 | ## Jenkins Cli 3 | 4 | ### 產生 SSH Key 5 | 6 | ``` 7 | ssh-keygen -C kata 8 | ``` 9 | 10 | PS. 下列範例以檔名 `jenkins_kata` 為例 11 | 12 | ### 取得 cli 13 | 14 | ``` 15 | wget http://127.0.0.1:1234/jnlpJars/jenkins-cli.jar 16 | ``` 17 | 18 | ### 啟用 cli 19 | 20 | 設定 TCP port (Web Console: `管理 Jenkins` -> `設定全域安全性`) 21 | 22 | ![](images/cli_fix_tcp_port.png) 23 | 24 | 設定使用者 SSH Public Key (Web Console: `使用者` -> `kata(你的使用者名稱)` -> `設定` ) 25 | 26 | ![](images/cli_ssh_public_key.jpg) 27 | 28 | ### 呼叫 Cli 29 | 30 | ``` 31 | java -jar jenkins-cli.jar -s http://127.0.0.1:1234/ -i jenkins_kata help 32 | ``` 33 | 34 | * `-i` 後接的是 SSH Private Key 35 | * `help` 是查詢有哪些指定可用 36 | 37 | ``` 38 | add-job-to-view 39 | Adds jobs to view. 40 | build 41 | 建置作業,並可以依要等侯建置完成。 42 | cancel-quiet-down 43 | 取消 "quiet-down" 指令。 44 | clear-queue 45 | 清除建置佇列。 46 | connect-node 47 | 連線到指定節點。 48 | console 49 | Retrieves console output of a build. 50 | copy-job 51 | 複製作業。 52 | create-credentials-by-xml 53 | Create Credential by XML 54 | create-credentials-domain-by-xml 55 | Create Credentials Domain by XML 56 | create-job 57 | 建立新作業,由 stdin 讀取設定 XML 檔的內容。 58 | create-node 59 | Creates a new node by reading stdin as a XML configuration. 60 | create-view 61 | Creates a new view by reading stdin as a XML configuration. 62 | delete-builds 63 | 刪除建置記錄。 64 | delete-credentials 65 | Delete a Credential 66 | delete-credentials-domain 67 | Delete a Credentials Domain 68 | delete-job 69 | 刪除作業。 70 | delete-node 71 | 刪除指定節點。 72 | delete-view 73 | Deletes view(s). 74 | disable-job 75 | 停用作業。 76 | disconnect-node 77 | 中斷與指定節點的連線。 78 | enable-job 79 | 啟用作業。 80 | get-credentials-as-xml 81 | Get a Credentials as XML (secrets redacted) 82 | get-credentials-domain-as-xml 83 | Get a Credentials Domain as XML 84 | get-gradle 85 | List available gradle installations 86 | get-job 87 | 將作業定義 XML 傾印到 stdout 88 | get-node 89 | Dumps the node definition XML to stdout. 90 | get-view 91 | Dumps the view definition XML to stdout. 92 | groovy 93 | 執行指定的 Groovy Script。 94 | groovysh 95 | 以互動式 Groovy Shell 方式執行。 96 | help 97 | 列出所有可用的指令。 98 | install-plugin 99 | 由檔案、URL 或是更新中心安裝外掛程式。 100 | install-tool 101 | 自動安裝工具,將其位置列印到 stdout。只能在建置中呼叫。 102 | keep-build 103 | 永久保存這次建置。 104 | list-changes 105 | 印出指定建置的變更記錄。 106 | list-credentials 107 | Lists the Credentials in a specific Store 108 | list-credentials-context-resolvers 109 | List Credentials Context Resolvers 110 | list-credentials-providers 111 | List Credentials Providers 112 | list-jobs 113 | 列出指定視景或項目群組中的所有作業。 114 | list-plugins 115 | 輸出安裝的外掛程式清單。 116 | login 117 | 儲存目前的驗證資訊,接下來的指令都可以直接執行而不用輸入驗證資料。 118 | logout 119 | 刪除 login 指令儲存的驗證資料。 120 | mail 121 | 讀取 stdin 並將結果以 e-mail 方式傳送。 122 | offline-node 123 | 暫時不使用指定節點來建置,直到執行 "online-node" 指令為止。 124 | online-node 125 | Resume using a node for performing builds, to cancel out the earlier "offline-node" command. 126 | quiet-down 127 | 讓 Jenkins 沉澱一下,準備重新啟動。先不要再建置任何作業。 128 | reload-configuration 129 | 放棄所有記憶體裡的資料,由檔案系統中重新載入。適合在直接修改設定檔後使用。 130 | reload-job 131 | Reload job(s) 132 | remove-job-from-view 133 | Removes jobs from view. 134 | replay-pipeline 135 | Replay a Pipeline build with edited script taken from standard input 136 | restart 137 | 重新啟動 Jenkins 138 | safe-restart 139 | 安全的重新啟動 Jenkins 140 | safe-shutdown 141 | 讓 Jenkins 進入靜候模式,等到現有作業都完成後就將 Jenkins 停機。 142 | session-id 143 | Outputs the session ID, which changes every time Jenkins restarts. 144 | set-build-description 145 | 設定建置描述說明。 146 | set-build-display-name 147 | 設定建置的顯示名稱 148 | set-build-parameter 149 | Update/set the build parameter of the current build in progress. 150 | set-build-result 151 | 設定目前建置的結果。在建置中呼叫才有作用。 152 | set-external-build-result 153 | Set external monitor job result. 154 | shutdown 155 | 立即將 Jenkins 伺服器停機 156 | update-credentials-by-xml 157 | Update Credentials by XML 158 | update-credentials-domain-by-xml 159 | Update Credentials Domain by XML 160 | update-job 161 | 由 stdin 更新作業定義 XML。get-job 指令的相反 162 | update-node 163 | Updates the node definition XML from stdin. The opposite of the get-node command. 164 | update-view 165 | Updates the view definition XML from stdin. The opposite of the get-view command. 166 | version 167 | 輸出目前的版本。 168 | wait-node-offline 169 | 等候指定節點離線。 170 | wait-node-online 171 | 等候指定節點上線。 172 | who-am-i 173 | 產出您驗證以及權限資訊的報表 174 | ``` 175 | --------------------------------------------------------------------------------