How do you run a build step/stage only if building a specific branch?
For example, run a deployment step only if the branch is called deployment
, leaving everything else the same.
This question is related to
jenkins
groovy
jenkins-pipeline
Just use if
and env.BRANCH_NAME
, example:
if (env.BRANCH_NAME == "deployment") {
... do some build ...
} else {
... do something else ...
}
According to other answers I am adding the parallel stages scenario:
pipeline {
agent any
stages {
stage('some parallel stage') {
parallel {
stage('parallel stage 1') {
when {
expression { ENV == "something" }
}
steps {
echo 'something'
}
}
stage('parallel stage 2') {
steps {
echo 'something'
}
}
}
}
}
}
Source: Stackoverflow.com