Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joining environment variables in Jenkins pipeline / groovy

Tags:

jenkins

groovy

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

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

Generates 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 variations such as ...

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

or

TOX_DIR = "$TMPDIR/$BUILD_TAG"

or

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

only make matters worse.

What am I missng? Thanks....

like image 401
bowe Avatar asked Apr 12 '17 14:04

bowe


People also ask

How do I get environment variables in Groovy Jenkins?

In "Manage Jenkins" -> "Configure System" -> "Global Properties" -> "Environment Variables" I added "ALL_NODES_ENVVAR".

How do I set environment variables in Groovy?

Download a binary distribution of Groovy and unpack it into some folder on your local file system. Set your GROOVY_HOME environment variable to the directory where you unpacked the distribution. Add GROOVY_HOME/bin to your PATH environment variable. Set your JAVA_HOME environment variable to point to your JDK.


1 Answers

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

environment{
    MESSAGE = "release-staging-${BUILD_TIMESTAMP}"
}
like image 150
HongerTrollie Avatar answered Oct 17 '22 04:10

HongerTrollie