栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Jenkinsfile中捕获手动UI取消作业

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Jenkinsfile中捕获手动UI取消作业

非声明性方法:

当您中止管道脚本生成时,

org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
将引发类型异常。
catch
阻塞释放资源,然后重新引发异常。

import org.jenkinsci.plugins.workflow.steps.FlowInterruptedExceptiondef releaseResources() {    echo "Releasing resources"    sleep 10}node {    try {        echo "Doing steps..."        sleep 20    } catch (FlowInterruptedException interruptEx) {        releaseResources()        throw interruptEx    }}

声明式方法(更新11/2019):

相同,但一个内

script {}
的块
steps
stage
。不是最巧妙的解决方案,而是我已经测试并开始工作的解决方案。

在最初回答时,没有条件

aborted
cleanup
后置条件(而IIRC仅
pipeline
具有后置条件,但
stage
没有条件)。

根据Jenkins声明性管道文档,在

post
部分下:

cleanup

在评估所有其他发布条件之后,无论管道或阶段的状态如何,都请在此发布条件中运行步骤。

因此,无论管道是否中止,这都是释放资源的好地方。

def releaseResources() {    echo "Releasing resources"    sleep 10}pipeline {    agent none    stages {        stage("test") { steps {     parallel (         unit: {  node("main-builder") {      script {          echo "Doing steps..."          sleep 20      }  }         }     ) } post {     cleanup {         releaseResources()     } }        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/392188.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号