Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
934 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 Answer

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...