Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

jenkins acess environment variables in environment declaration

So I have an environment in a Jenkins declarative pipeline script that looks something like this:

pipeline {
    environment {
        PATH1 = 'C:\Users\Administrator\Documents'
        PATH2 = '${env.PATH1}\more_stuff'
    }
    // etc...

But when I try to access PATH2 in anything, it transcribes the literal "${env.PATH1}" into it rather that the environment variable PATH1.

I have tried ${env.PATH1}, ${PATH1}, %PATH1%, but none of them work. How do I access environment variables while declaring other environment variables?

question from:https://stackoverflow.com/questions/65836848/jenkins-acess-environment-variables-in-environment-declaration

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I will assume you are trying to use Groovy string interpolation.

Groovy string interpolation is only performed on double quoted strings, not single quoted strings.

I believe what you want is

PATH2 = "${env.PATH1}\more_stuff"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...