Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JCConf2016 Jenkins Pipeline

JCConf2016 Jenkins Pipeline

JCConf 2016 For Jenkins Pipeline, see: https://github.com/qrtt1/JCConf2016_JenkinsPipeline

Ching Yi Chan

October 11, 2016
Tweet

More Decks by Ching Yi Chan

Other Decks in How-to & DIY

Transcript

  1. 什麼是 Pipeline • Delivery Pipeline (from Continuous Delivery) • Jenkins

    Workflow Plugins • Job Workflow Pipeline • Pipeline 由多個 Step 組成,並且⽀支援 Pause/Resume • Pipeline 內的狀態必需可序列化 (Serializable) • 或宣告為不必列⼊入狀態 @NonCPS 的 function
  2. 為什麼是 Pipeline • 依然是 Jenkins Job 的⼀一種,依然很 FreeStyle。 • 為的是

    Pipeline as Code • 它是 groovy DSL (domain specific language) و͉છՓ ˢ FreeStyle һ FreeStyle
  3. Pipeline DSL • Jenkins 的 Pipeline 介紹
 https://jenkins.io/solutions/pipeline/ • Pipeline

    寫作教學
 https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md • Pipeline 設計說明
 https://github.com/jenkinsci/workflow-cps-plugin/blob/master/README.md • Pipeline Steps Reference
 https://jenkins.io/doc/pipeline/steps/ • Pipeline 最佳實踐
 https://www.cloudbees.com/blog/top-10-best-practices-jenkins-pipeline-plugin ˴ࠅ޶வࡈ ༾Ցਪᕚݟவࡈ
  4. 建⽴立 Pipeline Job • Pipeline Script from in-place editor •

    Pipeline Script from SCM • Multi-branch Pipeline (from SCM) પᑥԴ͜4$.ٙ˙ό ቇΥఊਖ਼ࣩdʔΝචݬٙ1JQFMJOFІਗܔͭ සપᑥᏐ͜׵ᗇ᜕4DSJQUႧج
  5. Steps: node, stage, echo node { stage ('checkout') { echo

    'checkout from git' } stage ('build') { echo 'build' } // … skip … } ίࡳɓ̨ዚኜൺ ࡳɓࡈචݬ ਂԬʡჿ
  6. Steps: git stage ('checkout') { echo 'checkout from git' git

    url: 'https://my-scm/path/my-project.git' branch: 'master' } optional
  7. Steps: dir, pwd, sh (bat) dir ('project') { pwd() stage

    ('build') { sh """gradle clean build""" } stage ('test') { sh """gradle check""" } // … skip … }
  8. Steps: step, archiveArtifacts stage ('archive') { step([$class: 'ArtifactArchiver', 
 artifacts:

    "build/**/*.war", 
 fingerprint: true]) } stage ('archive') { archiveArtifacts 
 artifacts: "build/**/*.war", 
 fingerprint: true } ᔚٙᄳج อٙᄳج requires Jenkins 2.2+ with newer plugins
  9. Refactoring Pipeline • 使⽤用 Function 合併多個 steps 為⼀一個有意義的動作 • 實作新的

    Pipeline Step • 使⽤用 Pipeline Shared Libraries Ыဵə෗k ೌج༨1JQFMJOF4DSJQUԴ͜ ̥ঐપญl https://github.com/jenkinsci/workflow-cps-global-lib-plugin https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Shared+Groovy+Libraries+Plugin
  10. Pipeline Shared Library • 使⽤用⽅方法 • 啟⽤用 Jenkins ssh (因為

    Jenkins 內建的 git repo ⺫⽬目前僅能 ssh auth) • 安裝 Plugin (id: workflow-cps-global-lib) • 使⽤用 git 指令 commit & push 提交 Shared Library 並在 Pipeline Script 開始使⽤用 https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+SSH XFCDPOTPMFฤరQMVHJOҬʔՑd͜DMJٜટܲༀыl
  11. Pipeline 使⽤用⼼心得 • Pipeline as Code 可以⽅方便版本管理 • 內建的 Pipeline

    Step 不夠多,得常得依賴 sh 或 bat 呼叫外部指令。 • 間接使⽤用 DevOps Tool 處理 • Ansible, Chef, Puppet • Ant, Maven, Gradle