我们有用于 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/