jenkins - 如果座席离线,如何跳过一个阶段?

标签 jenkins jenkins-pipeline jenkins-groovy

在我的管道中,我有一个检查特定计算机(节点)是否离线的阶段。如果是,我想跳过下一阶段。但是,下一阶段设置为使用离线代理,因此似乎无法检查When子句。

这是我的管道的简化版本:

pipeline {
    agent none

    environment {
        CONTINUERUN = true
    }

    stages {
        stage('Check Should Run') {
            agent any
            steps {
                script {
                    CONTINUERUN = false
                }
            }
        }

        stage('Skip this stage') {
            agent {
                label 'offlineAgent'
            }
            when {
                expression {
                    CONTINUERUN
                }
            }
            steps {
                //Do stuff here
            }
        }
    }
}

当我运行它时,构建只是卡在“跳过此阶段”阶段。我假设,因为代理离线。当已知代理处于离线状态时,如何跳过此阶段?

最佳答案

为了在分配代理之前评估表达式,您需要将 beforeAgent 指令添加到 when block 。

documentation的相关部分:

Evaluating when before entering agent in a stage

By default, the when condition for a stage will be evaluated after entering the agent for that stage, if one is defined. However, this can be changed by specifying the beforeAgent option within the when block. If beforeAgent is set to true, the when condition will be evaluated first, and the agent will only be entered if the when condition evaluates to true.

关于jenkins - 如果座席离线,如何跳过一个阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58394325/

相关文章:

jenkins - 如何操作 Jenkins 管道作业的构建结果(返回 'SUCCESS' )?

Jenkins 从 GitHub 构建 PR 失败

jenkins-pipeline - 声明性 Jenkins 管道中的引用变量

jenkins - 如何在作为容器运行的 Jenkins 中运行 Docker

jenkins - 如何将构建 Artifactory 的快照版本上传到 Artifactory 中的 gradle 存储库

javascript - 如何使用远程服务器上的浏览器进行自动化测试

jenkins-pipeline - 如何修复 - stageResult 设置为 FAILURE 但仍然在 jenkins 中获得成功

shell - 将 shell 变量与 Jenkinsfile 中的常规变量混合并匹配

jenkins - 如何使用 ${currentBuild.result} 指示 "SUCCESS"而不是 "null"

jenkins - GKE : Multi-stage dockerfiles inside Jenkins