如果Jenkinsfile中的构建失败,有没有办法执行清理(或回滚)?
我想通知我们的Atlassian Stash实例构建失败(通过curl
在正确的URL处执行).
基本上,当构建状态设置为失败时,它将是一个后续步骤.
我应该用try {} catch ()
吗?如果是这样,我应该捕获哪种异常类型?
我有一个在现场运行的Jenkins服务器,它使用Jenkins文件管理一个管道,该管道使用并行测试执行器插件在几个代理上运行所有JUnit测试以加快测试速度.我们有一个刀片服务器(比买一个便宜!)并且我们的测试从接近2小时到22分钟加速.JUnit插件适用于并行测试.
然而,Jacoco Plugin却没有.所以我试图将覆盖文件合并到一个文件,以便Jacoco插件可以发布覆盖结果.Stash/unstash正在存储源代码,但是当我尝试存储不同的Jacoco输出文件以在master上取消它们时,它无法正常工作.
有什么想法吗?
这是我的Jenkinsfile:
#!/usr/bin/env groovy
def branch
def hash
node('remote') {
sh 'echo starting'
branch = env.gitlabBranch ?: '**'
echo "Branch: $branch"
checkout([$class: 'GitSCM',
branches: [[name: "$branch"]],
extensions: [
[$class: 'PruneStaleBranch'],
[$class: 'CheckoutOption', timeout: 120],
[$class: 'CloneOption', depth: 0, noTags: true, shallow: true, timeout: 180]
],
doGenerateSubmoduleConfigurations: false,
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'gitlabLabptop', url: 'git@gitlab.com:protocase/my_project_url.git']]
]
)
hash = sh (script: 'git rev-parse HEAD', returnStdout: true).trim()
### - this stash works fine -###
stash name: 'sources', includes: '**', …
Run Code Online (Sandbox Code Playgroud)