Jenkins - Pipeline as Code - 簡介 - iT 邦幫忙 | jenkins pipeline指定agent
Jenkins是個歷史悠久的CI/CD工具,從Jenkins2.0開始正式推展Pipeline,有別於以往使用WebUI操作的特性,導向PipelineasCode的實踐。透過在原始碼專案新增一個Jenkinsfile的檔案,將Pipeline的流程都寫在檔案內。Pipeline就是流水線的意思,一個完整的流程可以包含Build(建置)、Test(測試)、Deploy(部署)三個state(階段),每個公司或產品的CD流程所包含的state可能不同,可以依需要各別調整。簡單Pipeline範例(source)[1]pipeline{agentanystages{stage(Build){steps{echoBuilding..}}stage(Test){steps{echoTesting..}}stage(Deploy){...
Jenkins 是個歷史悠久的 CI / CD 工具,從 Jenkins 2.0 開始正式推展 Pipeline,有別於以往使用 Web UI 操作的特性,導向 Pipeline as Code 的實踐。透過在原始碼專案新增一個 Jenkinsfile 的檔案,將 Pipeline 的流程都寫在檔案內。
Pipeline 就是流水線的意思,一個完整的流程可以包含 Build (建置)、 Test (測試)、Deploy (部署) 三個 state (階段),每個公司或產品的 CD 流程所包含的 state 可能不同,可以依需要各別調整。
簡單 Pipeline 範例 (source)[1]
pipeline { agent any stages { stage(Build) { steps { echo Building.. } } stage(Test) { steps { echo Testing.. } } stage(Deploy) { steps { echo Deploying.... } } } }Jenkinsfile 的開頭宣告
指定什麼條件的 agent 可以執行這個專案,any 表示不指定,任意 agent 都可以執行,這個設定相當於 UI 上的限制專案執行節點,可以用 label 指定 agent 標籤,假如指定 test 的話
agent { label test }另一種情況,如果在不同 state 要分別指定不同 agent 的時候,最上層的 agent 會指定為 none,然後在各自 state 要指定 agent
代表流水線的各個階段,範例中為 ...