Issue
I am trying to do a conditional step on Jenkins to see if the String Parameter contains a certain word.
I have a string for PLATFORM
. The values in it can be Windows, Mac, Linux
I want to run a certain step if the value of the parameter contains Linux.
How can I do that? I downloaded the Jenkins plugin for conditional step but it doesn't have a contains clause.
Solution
You can use when directive of Jenkins to achieve the conditional steps.
Example:
pipeline {
agent any
stages {
stage ('Windows RUN') {
when {
expression { params.PLATFORM == 'Windows' }
}
steps {
echo "Hello, Windows"
}
}
stage ('Mac RUN') {
when {
expression { params.PLATFORM == 'Mac' }
}
steps {
echo "Hello, Mac"
}
}
stage ('Linux RUN') {
when {
expression { params.PLATFORM == 'Linux' }
}
steps {
echo "Hello, Linux"
}
}
}
}
Output:
Answered By - Sourav Atta
Answer Checked By - Clifford M. (JavaFixing Volunteer)