简体   繁体   中英

In Jenkins pipeline some environment variables are having null value

In Jenknsfile I want to check CHANGE_AUTHOR, CHANGE_AUTHOR_EMAIL and some more variables. But when I run it shows null value.

Code snip from Jenkinsfile Code:

if (env.CHANGE_ID){
echo "CHANGE_ID : ${env.CHANGE_ID}"
echo "CHANGE_URL : ${env.CHANGE_URL}"
echo "CHANGE_TITLE : ${env.CHANGE_TITLE}"
echo "CHANGE_AUTHOR : ${env.CHANGE_AUTHOR}"
echo "CHANGE_AUTHOR_DISPLAY_NAME : ${env.CHANGE_AUTHOR_DISPLAY_NAME}"
echo "CHANGE_AUTHOR_EMAIL : ${env.CHANGE_AUTHOR_EMAIL}"
echo "CHANGE_TARGET : ${env.CHANGE_TARGET}"
echo "BRANCH_NAME : ${env.BRANCH_NAME}"
...
...

Output of pipeline:

[Pipeline] echo
CHANGE_ID : 69
[Pipeline] echo
CHANGE_URL : null
[Pipeline] echo
CHANGE_TITLE : Generic jenkinsfile
[Pipeline] echo
CHANGE_AUTHOR : null
[Pipeline] echo
CHANGE_AUTHOR_DISPLAY_NAME : null
[Pipeline] echo
CHANGE_AUTHOR_EMAIL : null
[Pipeline] echo
CHANGE_TARGET : null
[Pipeline] echo
BRANCH_NAME : PR-69

How can I get the variables value which shows null?

Are you using a multibranch pipeline job? Those variables are only available in multibranch. See the env section on this page of your Jenkins instance:

http://Jenkins.server.url/pipeline-syntax/globals

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