简化的管道看起来像:
1. build
2. unit test
3. deploy to dev
4. integration tests
5. deploy to prod
对于步骤#5,我设置了Jenkins管道输入命令。我们不会在每次提交时都进行部署,所以如果我们中止所有这些工作,它将有一个灰色构建的大清单。是否可以使用跳过选项,以便构建仍然可以显示为 green blue?
答案 0 :(得分:3)
我刚刚找到了一个更好的解决方案。您可以使用返回值来访问输入的结果。用户必须选中该复选框才能运行可选阶段。否则跳过阶段的步骤。如果你跳过整个舞台,舞台将会消失并“清理”舞台视图的历史。
stage('do optional stuff?') {
userInput = input(
id: 'userInput', message: "Some important question?", parameters: [
booleanParam(defaultValue: false, description: 'really?', name: 'myValue')
])
}
stage('optional: do magic') {
if (userInput) {
echo "do magic"
} else {
// do what ever you want when skipping this build
currentBuild.result = "UNSTABLE"
}
}
答案 1 :(得分:2)
你不能做这样的事情,无论你从输入中选择什么,它都将是蓝/绿色,你可以根据它运行部署吗?
def deployToProduction = true
try{
input 'Deploy to Production'
}catch(e){
deployToProduction = false
}
if(deployToProduction){
println "Deploying to production"
}
答案 2 :(得分:1)
怎么样:
stage('Deploy') {
when { branch 'master' }
steps {
sh '...'
}
}
}
该阶段将跳过其他分支上的提交,并且为绿色。
答案 3 :(得分:-3)
您可以使用下游/上游配置设置作业,而不是使用管道作为代码Jenkins2功能。
构建 - >单元测试 - >部署到Dev - >集成测试 - >促进产品 - >部署到Prod
目前,它可以更好地控制您希望生产哪种版本的管道。 为了获得更高的可见性,您可以使用Delivery-Pipeline-Plugin配置Delivery Pipeline。