当没有要推送到GitHub的更改时,阻止jenkins pipeline阶段失败
帮助我阻止一个阶段失败,阻止下一个阶段失败,从而阻止整个构建。问题已经到了无法提交GitHub更改的阶段。代码如下:当没有要推送到GitHub的更改时,阻止jenkins pipeline阶段失败,jenkins,groovy,jenkins-pipeline,stage,Jenkins,Groovy,Jenkins Pipeline,Stage,帮助我阻止一个阶段失败,阻止下一个阶段失败,从而阻止整个构建。问题已经到了无法提交GitHub更改的阶段。代码如下: pipeline { agent { label 'master' } environment { // 'This value is exported to all commands in this stage' blah blah.. blah... } stages { stage('Check Environment')
pipeline {
agent { label 'master' }
environment {
// 'This value is exported to all commands in this stage'
blah
blah..
blah...
}
stages {
stage('Check Environment') {
steps {
sh "echo 'Build_Id: ' $BUILD_ID"
sh "echo 'Job_Name: ' $JOB_NAME"
sh "echo 'Build_Name: ' $BUILD_NAME"
sh "echo 'Current Branch Name: ' $BRANCH"
}
}
stage('Checkout Source Code') {
steps {
git branch: 'develop', url: 'git@github.com:something-some/otherthing.git'
}
}
stage('Snapshot - Version Upgrade') {
environment {
VERSION = readMavenPom().getVersion()
}
steps {
script {
sh '''
#!/bin/bash -xe
echo $VERSION
mvn build-helper:parse-version versions:set versions:commit '-DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}'
git status
git add .
MVN_VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
git commit -m "Jenkins version upgrade - ${MVN_VERSION}"
git push --set-upstream origin $BRANCH
'''
}
}
}
stage('Test Release - Deploy Packages To Artifactory') {
steps {
script {
sh '''
blah
more blah..
'''
}
}
}
当阶段(“快照-版本升级”)中没有更改时-阶段失败,如何阻止其失败,请帮助
以下是日志中失败的代码段:
[INFO]
[INFO] --- versions-maven-plugin:2.5:commit (default-cli) @ Integrityv1 ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Some project Parent ................................ SUCCESS [ 0.010 s]
[INFO] Child Proj1......................................... SUCCESS [ 0.007 s]
[INFO] Child Proj2......................................... SUCCESS [ 0.007 s]
[INFO] Child Proj3......................................... SUCCESS [ 0.007 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:07 min
[INFO] Finished at: 2018-07-13T13:25:37+01:00
[INFO] Final Memory: 27M/304M
[INFO] ------------------------------------------------------------------------
+ git status
On branch develop
nothing to commit, working directory clean
+ git add .
+ mvn -q -Dexec.executable=echo -Dexec.args=${project.version} --non- recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec
+ MVN_VERSION=1.0.2
+ git commit -m Jenkins version upgrade - 1.0.2
On branch develop
nothing to commit, working directory clean
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test Release - Deploy Packages To Artifactory)
Stage "Test Release - Deploy Packages To Artifactory" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Publish to Windows Share)
Stage "Publish to Windows Share" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Delete Target)
Stage "Delete Target" skipped due to earlier failure(s)
只有在发生更改时,才能执行
commit
和push
:
if [ ! -z "$(git status --porcelain)" ]; then
git commit -m "Jenkins version upgrade - ${MVN_VERSION}"
git push --set-upstream origin $BRANCH
fi
查看您是否不熟悉
--ceral
是否可以添加整个输出?@AutomatedOwl从日志中添加了一个片段