Combining environment variables in Jenkins / groovy pipeline

I'm trying to set a couple of environment variables in a Jenkinsfile, but my Java / Groovy -ness flaw seems to be failing ...

pipeline {
    agent any
    environment {
        TMPDIR = /mnt/storage/build
        TOX_DIR = $TMPDIR/$BUILD_TAG
    }
...

      

Throws the following error on the console ...

WorkflowScript: 7: Environment variable values can only be joined together with +s. @ line 7, column 26.
       TOX_DIR = $TMPDIR/$BUILD_TAG

      

Other options such as ...

TOX_DIR = "$TMPDIR" + "/" + "$BUILD_TAG"

      

or

TOX_DIR = "$TMPDIR/$BUILD_TAG"

      

or

TOX_DIR = "${TMPDIR}/${BUILD_TAG}"

      

only makes the situation worse.

What am I missing? Thank....

+3


source to share


2 answers


Using Jenkins v2.89.2 - Instead of using single quotes, double quotes worked for me.



environment{
    MESSAGE = "release-staging-${BUILD_TIMESTAMP}"
}

      

+2


source


nm ... the answer is clearer than I thought, just the missing quotes ...



....
environment {
    TMPDIR = '/mnt/storage/work'
    TOX_DIR = '${TMPDIR}/${BUILD_TAG}'
}
...

      

0


source







All Articles