I am using a Jenkins File which has comma separated multiple values as Active Choice parameter and replacing the comma with ” or @” inside Environment block. Then passing the Environment variable value in a bat command. My goal is to pass more than one Cucumber Tag values (not using comma) in a bat command.
Jenkins file has the following scripts –
parameters {
activeChoice choiceType: 'PT_CHECKBOX', filterLength: 1, filterable: false, name: 'Tags', script: groovyScript(fallbackScript: [classpath: [], oldScript: '', sandbox: false, script: ''], script: [classpath: [], oldScript: '', sandbox: false, script: '''return [
'Login',
'ContractUpload',
'contractOrderGuide'
]'''])
}
environment {
Tags1 = "${Tags.replaceAll('\,', ' or @')}"
}
stages
{
stage('build')
{
steps
{
script
{
if (JOB_NAME == 'RegTest')
{
echo "Before replacing Tags are: ${Tags}"
echo "After replace Tags are: ${Tags1}"
bat 'mvn -f pom.xml clean exec:java -Dexec.cleanupDaemonThreads=false -Dexec.classpathScope="test" -Dcucumber.filter.tags="@%${env.Tags1}%"'
}
}
}
}
}
Jenkins Job on UI is as follows –
Active Choice Parameters where user can select multiple check boxes
I have selected more than one values as Active Choice Parameters.
When I print “${Tags1}” and “${Tags}” variables, I am getting the correct results.
I hit BUILD on the UI, Jenkins starts building the job and “-Dcucumber.filter.tags=”@” ” is not getting desired values, “${env.Tags1}” is empty when used in a bat command.
Outputs:
Before replacing Tags are: ContractUpload,contractOrderGuide
[Pipeline] echo
After replacing Tags are: ContractUpload or @contractOrderGuide
[Pipeline] bat
C:ProgramDataJenkins.jenkinsworkspaceRegtest>mvn -f pom.xml clean exec:java -Dexec.cleanupDaemonThreads=false -Dexec.classpathScope=”test” -Dcucumber.filter.tags=”@”
After replacing the comma with ” or @” – multiple Cucumber Tag values are not passed in the bat command, “-Dcucumber.filter.tags” has only “@” as output and “${env.Tags1}” is empty in bat command. I tried with “${Tags1}” but result is same.
I am expecting the output as
bat ‘mvn -f pom.xml clean exec:java -Dexec.cleanupDaemonThreads=false -Dexec.classpathScope=”test” -Dcucumber.filter.tags=”@ContractUpload or @contractOrderGuide” ‘
where “-Dcucumber.filter.tags” should have the value as “@ContractUpload or @contractOrderGuide”.
Any help will be appreciated.
Thanks!
Supriyo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.