简体   繁体   中英

Jenkinsfile: Set environment variable based on other environment variable (Windows)

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM