In my jenkins pipeline I check a parameter EnvironmentName
. If this is not valid and another condition is true, I want to set this to a default value like "myname"
In all it is not a good way to change Parameter so I set a global var BUILDPATTERN
and want to fill this with namespacepattern
out of a shell script. But it looks like the shell script to not return any value to Stdout. In the tutorials the right command is echo
I understand.
parameters{
string(name: 'EnvironmentName', defaultValue: '', description: '')
}
environment{
BUILDPATTERN = "${EnvironmentName}"
}
stages{
stage('Prepare'){
environment {
namespacepattern = sh(returnStdout: true, script: '''
export LC_COLLATE=C #To make regex case sensitiv
DN1123REGEX='^[a-z0-9]([-a-z0-9]*[a-z0-9])$\'
if [[ ! "${EnvironmentName}" =~ ${DN1123REGEX} ]]
then
if [[ "${Cleanup_Instance}" == "true" ]]
then
echo "myname"
else
println "EnvironmentName is not in an valid format"
exit 1
fi
else
echo "${EnvironmentName}"
fi
''').trim()
BUILDPATTERN=namespacepattern
}
}
stage('Build'){
steps {
script {
echo "${BUILDPATTERN}"
}
}
}
In all BUILDPATTERN is empty later. Anyone can explain what my problem is here?