Jenkins Declarative Pipeline 1.3 の新機能紹介
Jenkins Declarative Pipeline 1.3 の新機能がJenkinsの公式ブログに上がっていました。
Declarative Pipeline 1.3からはpipeline でステージのネストができるようになったらしい。Sequential Stages というみたいです。
何ができるの?
- 複数のステージをparallelで実行できるようになった。
- これに伴いステージの入れ子もできるようになった。
サンプル
https://github.com/sakamaki-y123/jenkins-continuous-delivery/blob/master/pipeline/decrative-pipeline/pipeline_17_nested_stage.groovy
def SAMPLE_YAML = """\
name:
first: ""
last: ""
dates:
birth: ""
"""
def yamlData
pipeline {
agent any
environment {
fileName = "sample.yml"
}
stages {
stage('1 prepare') {
stages {
stage("1-1 read yaml") {
steps {
script{
yamlData = readYaml text: "${SAMPLE_YAML}"
}
}
}
stage("1-2 write yaml") {
steps {
script {
yamlData.name.first = "Ichiro"
yamlData.name.last = "Sato"
yamlData.dates.birth = "1980-01-01"
writeYaml file: fileName, data: yamlData
}
}
}
}
}
stage('2 archive ') {
steps {
archiveArtifacts fileName
}
}
}
}
こんな感じでサンプルを書いてみました。
pipeline 1.3まではこれで実行してもエラーになってしまいました。
WorkflowScript: 18: Unknown stage section "stages". Starting with version 0.5, steps in a stage must be in a steps block. @ line 18, column 9. stage('1 prepare') { ^ WorkflowScript: 18: No "steps" or "parallel" to execute within stage "1 prepare" @ line 18, column 9. stage('1 prepare') { ^ 2 errors
1.3から上記の書き方でstageを入れ子にすることができるようになります。
ただGUI上では入れ子になっていることは表現されませんでした。
Stage View
Blue Ocean
所感
Stageの入れ子ができるようになったので今までよりもパイプラインの書き方は柔軟にできるようになったんじゃないかなと思います。かゆい所に少し手が届くようになった感じ。ただ画面の描画では入れ子のステージがうまく表現されないのでこの点に関しては今後の改善に期待します。