如何在詹金斯管道中运行特定阶段

时间:2019-04-08 16:19:01

标签: jenkins-pipeline

如何在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.如何实现?

1 个答案:

答案 0 :(得分:0)

您可以在每个要跳过的阶段使用when表达式。变量checkoutCoderunSonarScandeployNexusArtifact可以静态或动态设置为环境变量。

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' } }
    ...
}
相关问题