I want to use when
on branch
condition. The Jenkinsfile is like this
stages{
stage('Checkout project branch master'){
steps{
withCredentials([sshUserPrivateKey(credentialsId: 'credential', keyFileVariable: 'CREDENTIAL')]) {}
git branch: 'develop', credentialsId: 'credential', url: 'git@bitbucket.org:user/demopipelinejenkinsfile.git'
}
}
stage('develop'){
steps {
echo 'on branch develop`
}
}
stage('any_branch'){
environment {
GIT_BRANCH = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim()
}
steps{
echo "${env.GIT_BRANCH}"
}
}
}
The console output shows that the stage develop
is skipped due to condition. However, the last stage still echoes the current branch is "develop"
Question
How to use when
with branch
in Pipeline project (not Multibranch project)
develop
doesn't have a when condition as seen above ? Are you able to provide the when condition you are using ? You can use something likewhen { branch 'develop' }
– ben5556 Nov 4 '18 at 0:18