简体   繁体   English

如果我的构建阶段在jenkins管道中失败,如何跳过阶段?

[英]how to skip the stage if my build stage fails in jenkins pipeline?

I am using three stages here , In this if my second stage Build fails it should skip the third stage copy . 我在这里使用三个阶段,如果我的第二阶段Build失败,它应该跳过第三阶段副本 may i know how to use conditions here in pipeline job? 我可以知道如何在管道工作中使用条件吗?

node('') {
stage ('clone'){
    Build job : 'Job1'
  }
stage ('Build'){
parallel(firstTask: {
    stage ('Job2'){
    build job: 'Job2', propagate: true 
    }
}, secondTask: {
    stage ('Job3'){
    build job: 'Job3', propagate: true
    }
})
stage ('copy'){
    build job: 'copy'
}
}
}   
  1. First and foremost you will need to declare stage under stages and not under node. 首先,您需要在阶段下而不是在节点下声明阶段。 As per default behaviour of pipeline, if a build fails in a stage, it will automatically skip next stages. 根据管道的默认行为,如果构建在阶段中失败,它将自动跳过下一阶段。
  2. There are lot of options for using conditions in pipeline. 在管道中使用条件有很多选择。 One of the option I often use is when {} . 我经常使用的选项之一是when {} Here is an example- 这是一个例子 -
Jenkinsfile (Declarative Pipeline)
pipeline {
    agent any
    stages {
        stage('Example Build') {
            steps {
                echo 'Hello World'
            }
        }
        stage('Example Deploy') {
            when {
                branch 'production'
            }
            steps {
                echo 'Deploying'
            }
        }
    }
}

For more details and options, refer this documentation - https://jenkins.io/doc/book/pipeline/syntax/ 有关更多详细信息和选项,请参阅此文档 - https://jenkins.io/doc/book/pipeline/syntax/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何跳过 jenkins 管道中的一个阶段 Build based on a Jenkins trigger - How to Skip a stage in a jenkins pipeline Build based on a Jenkins trigger 如果复制失败,Jenkins 管道跳过阶段 - Jenkins pipeline skip stage if copying fails Jenkins:如何跳过多分支管道中的特定阶段? - Jenkins: How to skip a specific stage in a multibranch pipeline? 如何仅在 jenkins 管道中的阶段 A 失败时触发阶段 B - How to trigger stage B only when stage A fails in jenkins pipeline Jenkins:如何根据复选框参数条件跳过 Jenkins 管道中的阶段? - Jenkins: How to skip a stage in Jenkins pipeline based on a checkbox parameter condition? Jenkins 构建管道 - 在阶段重启 - Jenkins Build Pipeline - Restart At Stage 有没有一种方法可以有条件地跳过整个詹金斯管道(不是阶段) - Is there a way to skip whole Jenkins Pipeline (not a stage) on conditional Jenkins 基于变量的流水线阶段跳跃 - Jenkins Pipeline stage skip based on variable 脚本化 Jenkins 管道,跳过阶段的并行部分 - Scripted Jenkins pipeline, skip parallel part of stage Jenkins 管道:如何在阶段 x 中捕获错误,但跳过下一阶段 (y),但仍然运行最后一个阶段 (z)? - Jenkins Pipeline: How do I catch an error in stage x, but skip the next stage (y), but still run the last stage (z) after that?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM