bash - 詹金斯管道 - 出错时转到 postFailure 块
问题描述
伙计们,我有下面的 Jenkins 管道。我想运行所有阶段,因此我得到了catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')到位。我有一个脚本minion_notification.sh生成名为"jk_buildpass.txt"的文件。现在,我希望我的构建在条件if [ !-s jk_buildpass.txt ]匹配。使用出口 1,作业不会失败,并且后续阶段正在执行。任何想法?
pipeline = {
ansiColor('xterm') {
FILEVERSION = params.FILEVERSION.trim()
def remote = [:]
remote.name = 'xxx'
remote.host = '10.xxx.xx.x'
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: 'saltmaster', passwordVariable: 'password', usernameVariable: 'ops')]) {
remote.user = 'ops'
remote.password = password
stage (' Backup') {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh './minion_notification.sh "${FILEVERSION}" "Validate" "backupdb"'
sh(returnStdout: true, script: '''#!/bin/bash
if [ ! -s jk_buildpass.txt ];then
exit 1
else
echo "jk_buildpass is not empty"
fi
'''.stripIndent())
}
}
stage (' Uninstall') {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh './minion_notification.sh "${FILEVERSION}" "Validate" "IRMUninstall"'
sh(returnStdout: true, script: '''#!/bin/bash
if [ ! -s jk_buildpass.txt ];then
exit 1
else
echo "jk_buildpass is not empty"
fi
'''.stripIndent())
}
}
stage('Run DDMU') {
sh './minion_notification.sh "${FILEVERSION}" "jenkins-display"'
}
}
// sh './slk_notify.sh "Upgrade successfully completed for - ${FILEVERSION} " "*********** " "good" ":jenkins:"
}
}
postFailure = {
sh './slk_notify.sh " Upgarde failed for - ${FILEVERSION} " "danger" ":jenkinserror:"'
}
postAlways = {
echo 'Cleaning Workspace now'
env.WORKSPACE = pwd()
//sh "rm ${env.WORKSPACE}/* -fr"
}
node{
properties([
parameters([
string(name: 'FILEVERSION', defaultValue: '', description: 'Enter the file name to be process ')
])
])
try {
pipeline()
} catch (e) {
postFailure()
throw e
} finally {
postAlways()
}
}
解决方案
推荐阅读
- azure-active-directory - 如何使用 Graph API 按 Actor 过滤 Azure AD 审计
- cors - 从 Swagger Editor 发出请求时,如何避免 CORS 错误(“无法获取”或“未找到服务器或发生错误”)?
- design-patterns - keras中的继承与组合——为什么模型是从网络继承的
- wso2 - WSO2 ESB 数据服务
- ios - 在共享源之前从 iOS 应用程序中删除签名信息?
- css - 一个背景图像没有显示,而另一个是
- javascript - 材质 UI 浮动按钮操作
- python - 如何在张量流 CNN 中显示特征图(过滤层)?
- css - ggiraph:同一个ggplot上的不同悬停效果
- sql - 从度量表中过滤掉未完成的错误记录