jenkins 等待运行以条件并行阶段开始

8e2ybdfx  于 12个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(113)

下面是一个要复制的示例管道。使用Jenkins 2.414.1 w/ Blue Ocean 1.27.6。

pipeline {
    agent any
    parameters {
        booleanParam(name: 'IS_DEPLOY_LG', defaultValue: true, description: 'Deploy to LG')
        booleanParam(name: 'IS_DEPLOY_SM', defaultValue: true, description: 'Deploy to SM')
    }

    stages {
        stage ("Deploy") {
            parallel {
                stage('SM') {
                    when { expression { params.IS_DEPLOY_SM } }
                    steps {
                        script {
                            echo 'Running SM'
                            sleep 15
                        }
                    }
                }
                stage('LG') {
                    when { expression { params.IS_DEPLOY_LG } }
                    steps {
                        script {
                            echo 'Running LG'
                            sleep 15
                        }
                    }
                }
            }
        }
    }
}

当两个布尔参数都为真(选中)时,并行流水线阶段在流水线运行时按预期运行。

如果只有一个参数为真,Blue Ocean将在管道的持续时间内显示等待运行开始。
这似乎是一个bug,但不确定,管道代码有什么问题吗?

只有在管道完成后,它才会显示已完成的阶段。

njthzxwz

njthzxwz1#

我正要在Jenkins Jira上创建一个关于这个的bug ticket,但看起来已经有一个了-https://issues.jenkins.io/browse/JENKINS-48879。在评论中,建议的解决方案是添加一个虚拟阶段,这似乎有助于例如。-

pipeline {
    agent any
    parameters {
        booleanParam(name: 'IS_DEPLOY_LG', defaultValue: true, description: 'Deploy to LG')
        booleanParam(name: 'IS_DEPLOY_SM', defaultValue: true, description: 'Deploy to SM')
    }

    stages {
        stage ("Deploy") {
            parallel {
                stage('SM') {
                    when { expression { params.IS_DEPLOY_SM } }
                    steps {
                        script {
                            echo 'Running SM'
                            sleep 15
                        }
                    }
                }
                stage('LG') {
                    when { expression { params.IS_DEPLOY_LG } }
                    steps {
                        script {
                            echo 'Running LG'
                            sleep 15
                        }
                    }
                }
                stage('(Workaround)') {
                    steps {
                        sleep 10
                    }
                }
            }
        }
    }
}

相关问题