How can I list all the `env` properties within a Jenkins pipeline?

0 votes

Given a jenkins 2.1 build pipeline, jenkins injects a env variable into the node{}. For example, BRANCH_NAME can be accessed with

node {
    echo ${env.BRANCH_NAME}
    ...

I want to echo all env properties within the jenkins pipeline.

I'm looking for code like

node {
    for(e in env){
        echo e + " is " + ${e}
    }
    ...

which would echo something like

 BRANCH_NAME is myBranch2
 CHANGE_ID is 44
 ...
Aug 9, 2018 in Jenkins by Tyrion anex
• 8,280 points
131 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

One way of doing this is :

node {
echo sh(returnStdout: true, script: 'env')
// ..
}

Another way is:

According to Jenkins documentation for declarative pipeline use :

sh 'printenv'

And for Jenkins scripted pipeline use:

echo sh(script: 'env|sort', returnStdout: true)
answered Aug 9, 2018 by Sophie may
• 9,050 points

Related Questions In Jenkins

0 votes
1 answer
+4 votes
7 answers

How to set the pipeline name and description for a Jenkinsfile?

You can rename pipeline jobs in jenkins ...READ MORE

answered Oct 11, 2018 in Jenkins by Hannah
• 14,080 points
3,955 views
+5 votes
4 answers

How can I run a Jenkinsfile from a particular folder?

Consider the below points: The Freestyle project ...READ MORE

answered Mar 26, 2018 in Jenkins by anonymous
750 views
0 votes
1 answer

How can I create global macros and templates in jenkins job builder?

you can append the path to the ...READ MORE

answered Apr 2, 2018 in Jenkins by ajs3033
• 7,000 points
188 views
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer

How to trigger a Jenkins pipeline A in another Jenkins pipeline B?

You can run the following code, its ...READ MORE

answered Jul 5, 2018 in Jenkins by Sophie may
• 9,050 points
710 views
0 votes
1 answer

How can I exchange jobs between 2 different Jenkins instances?

java -jar jenkins-cli.jar -s http://server get-job myjob ...READ MORE

answered Jul 6, 2018 in Jenkins by Sophie may
• 9,050 points
23 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.