简体   繁体   English

在 Jenkins 管道 / groovy 中加入环境变量

[英]Joining environment variables in Jenkins pipeline / 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...我正在尝试在 Jenkinsfile 中设置几个环境变量,但是我缺乏 Java/Groovy-ness 似乎让我失望...

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....谢谢....

Using Jenkins v2.89.2 - Instead of using single quotes, double quotes worked for me.使用 Jenkins v2.89.2 - 而不是使用单引号,双引号对我有用。

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

nm... answer is saner than I thought, just missing quotes... nm...答案比我想象的要理智,只是缺少引号...

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

Solution: Error Environment variable values can only be joined together with '+'s means that you missed quotes .解决方案:错误Environment variable values can only be joined together with '+'s表示您错过了引号 just wrap quotes on string or string builder.只需在字符串或字符串生成器上加上引号。

environment {
    SOME_VAR = "Content"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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