Dan*_*ano 5 jenkins jenkins-pipeline
我正在尝试使用并行步骤进行后故障操作,但它永远不会起作用.
这是我的JenkinsFile:
pipeline {
agent any
stages {
stage("test") {
steps {
withMaven(
maven: 'maven3', // Maven installation declared in the Jenkins "Global Tool Configuration"
mavenSettingsConfig: 'maven_id', // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
mavenLocalRepo: '.repository')
{
// Run the maven build
sh "mvn --batch-mode release:prepare -Dmaven.deploy.skip=true" --> it will always fail
}
}
}
stage("testing") {
steps {
parallel (
phase1: { sh 'echo phase1' },
phase2: { sh "echo phase2" }
)
}
}
}
post {
failure {
echo "FAIL"
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这里的失败后行动有点用处......我看不到任何地方.
谢谢大家!问候
Ala*_*n47 11
经过几个小时的搜索,我发现了这个问题.你错过了什么(我也错过了)是catchError部分.
pipeline {
agent any
stages {
stage('Compile') {
steps {
catchError {
sh './gradlew compileJava --stacktrace'
}
}
post {
success {
echo 'Compile stage successful'
}
failure {
echo 'Compile stage failed'
}
}
}
/* ... other stages ... */
}
post {
success {
echo 'whole pipeline successful'
}
failure {
echo 'pipeline failed, at least one step failed'
}
}
Run Code Online (Sandbox Code Playgroud)
您应该将可能失败的每个步骤都包装到catchError函数中.这样做是:
build.result为FAILURE......最后一点很重要:你的post{ }块没有被调用,因为你的整个管道在它们甚至有机会执行之前就被中止了.
| 归档时间: |
|
| 查看次数: |
8549 次 |
| 最近记录: |