I'm trying to create a Jenkinsfile with environment variables that are based on other environment variables. This fails to work as the %PATH% in the example below is not translated correctly.
What is the proper syntax to get this working?
pipeline {
environment {
ENVTEST1 = '$PATH;c:\\additional\\path'
ENVTEST2 = '${PATH};c:\\additional\\path'
ENVTEST3 = '$env.PATH;c:\\additional\\path'
ENVTEST4 = '${env.PATH};c:\\additional\\path'
ENVTEST5 = '%PATH%;c:\\additional\\path'
}
agent any
stages {
stage ('Build'){
steps {
bat 'SET' // print all env vars
}
}
}
}
The result in the buildlog is this:
ENVTEST1=$PATH;c:\additional\path
ENVTEST2=${PATH};c:\additional\path
ENVTEST3=$env.PATH;c:\additional\path
ENVTEST4=${env.PATH};c:\additional\path
ENVTEST5=%PATH%;c:\additional\path
None of the above options seem to be working.
Can someone tell me how to define an environment variable based on another environment variable please?
CodePudding user response:
You should use with double quotes when concatenating strings like that.
"My name is $first $last"
Otherwise you can use the " " operator in this way:
'My name is ' first ' ' last