jenkins-pipeline - 如何在 Jenkins 管道中运行特定阶段
问题描述
如何在特定阶段运行Jenkins declarative pipeline
?
例子:
- 第 1 阶段 --> Gitlab 代码检查
- 阶段 2 --> Sonarqube 扫描
- 第 3 阶段 --> 部署 Nexus 工件
- 第 4 阶段 --> 强化检查
如果我想我run only the stage 3(Deploy Nexus artifact) without running the stage 1, 2 and 4.
怎么能做到这一点?
解决方案
您可以在要跳过的每个阶段使用when表达式。变量checkoutCode
, runSonarScan
,deployNexusArtifact
可以静态或动态设置为环境变量。
environment {
checkoutCode = true
runSonarScan = true
deployNexusArtifact = true
}
stage('Gitlab code Checkout') {
when { expression { "${checkoutCode}" == 'true' } }
...
}
stage('Sonarqube scan') {
when { expression { "${runSonarScan}" == 'true' } }
...
}
stage('Deploy Nexus artifact') {
when { expression { "${deployNexusArtifact}" == 'true' } }
...
}
推荐阅读
- python-3.x - python pywhatkit 模块需要很多时间来安装而不是在 linux 中安装
- java - springboot中带有aop的bytebuddy不起作用
- r - 图例标题对齐 (ggmap)
- reactjs - 如何创建多个字段,有他们的号码?
- python - 在 python 中将大类拆分为小类的性能提升
- python - Keras - layer.trainable = False 冻结层不起作用
- python - 将度数转换为数组内的弧度
- node.js - 为什么我不能捕捉到这些错误?
- typescript - 有条件的必填参数
- java - JDK 8 ('1.8.*') 错误的要求检查失败