Jenkins 管道用户输入 - 如果中止则操作

标签 jenkins groovy jenkins-pipeline

我们有用于 Jenkins 的 Groovy 脚本,带有“验证”(配置)步骤:

...
def deploy_prod_verify() {

    stage 'Verify'
    input id: 'Deploy', message: 'Is Blue node fine? Proceed with Green node deployment?', ok: 'Deploy!'

}
...

我的问题是 - 一切正常(即 - 如果按“部署!” - 下一阶段开始)。

但是 - 如果按下“中止”,我如何使用 Jenkins 运行另一个函数?

现在 - Jenkins 将中止当前的工作。我想改为运行另一个函数(“回滚”)。

我找到了一些文档 here ,但看不到与“中止”操作相关的任何内容。

我看到“Abort”将执行 Ajax 调用:

<a href="#" onclick="new Ajax.Request('http://<JENKINS HOST>/job/EU-api-staging-build/72/input/Deploy/abort'); return false">Abort</a>

而且据我了解 - 无论如何都无法处理此Deploy/abort

最佳答案

根据@MaTePe 的回答,您可以按照以下方式进行操作:

def deploy_prod_verify() {
    stage ('Verify'){
        try {
            input id: 'Deploy', message: 'Is Blue node fine? Proceed with Green node deployment?', ok: 'Deploy!'
            do whatever you need...
        } catch (error) {
            If an error is caught... do this...
        }
    }
}

关于Jenkins 管道用户输入 - 如果中止则操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40635524/

相关文章:

git - 带有两个 git 存储库的 Jenkinsfile

jenkins - 并行任务日志困惑

java - Jenkins Windows Slave JNLP 连接错误

git - 测试成功如何使用Jenkins推送到Github?

android - 应用程序 :mergeTestReleaseResourcesAAPT err(Facade for 495460572) :

groovy - Gradle并不真正遵守执行顺序

groovy - groovy中数组列表的总和

jenkins - 如何防止两个相同类型的管道 jenkins 作业在同一节点上并行运行?

spring - 在 Groovy 中使用 @Value Spring 注解

jenkins - 如何继续度过 Jenkins 声明式管道语法的失败阶段