3
votes

I have a parameterized pipeline build with one 'String' parameter BuildOutDir with value ${WORKSPACE}/out/.

My pipeline script is:

node ('windows') {
    stage ('Test') {
        echo "$WORKSPACE"
        echo "$BuildOutDir"
        }
}

Output is :

[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] echo
D:\jenkins\workspace\test_pipeline
[Pipeline] echo
${WORKSPACE}\out\
[Pipeline] }
[Pipeline] // stage

Is there a way to expand environment variable passed as build parameter ? This expands correctly in non-pipeline build jobs.

1
Eval.me("$BuildOutDir") should work... But can't you just pass \out and add it to WORKSPACE?tim_yates
@tim_yates ... I used WORKSPACE as an example for an environment variable. I tried Eval.me("$BuildOutDir"), it gives me an error hudson.remoting.ProxyException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1: unexpected token: @ line 1, column 18.${WORKSPACE}/out/ ^ 1 error . Not sure what i'm doing wrong. Thanks for the help.newbie

1 Answers

6
votes

You don't show the script or job that call this pipeline.

However, it is most likely due to incorrect string interpolation. In groovy, you need to use double quotes so variables get interpolated (= replaced). If instead you used simple quote, the param string will not be interpreted and your workspace variable will not be replaced. So basically what you want to do is replace the following line :

build job: 'yourPipeline', parameters: [string(name: 'BuildOutDir', value: '${WORKSPACE}')]

With :

build job: 'yourPipeline', parameters: [string(name: 'BuildOutDir', value: "${WORKSPACE}")]

in your calling pipeline. Again, the only difference is the double quotes instead of the single quotes aroung ${WORKSPACE} variable .