Git environment variables for use in executing Jenkins shell scripts
Asked Answered
N

3

16

Hope someone can help - I have the following plugin installed in my Jenkins instance - but I don't seem to be able to get hold of the Git variables below. I need these to complete our CI setup. Is there something that I'm missing?

I'm passing them in like:

ssh [email protected] "./build-pass.sh $GIT_BRANCH"

https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin

Environment variables

The git plugin sets several environment variables you can use in your scripts:

  • GIT_COMMIT - SHA of the current

  • GIT_BRANCH - Name of the branch currently being used, e.g. "master" or "origin/foo"

  • GIT_AUTHOR_EMAIL - Committer/Author Email

  • GIT_COMMITTER_EMAIL - Committer/Author Email

Nanice answered 14/7, 2014 at 21:11 Comment(1)
Are you running that ssh command from inside a Jenkins build (where the GIT_ variables should be available), or from a command line (where they won't be) ?Tumer
N
23

Ok I cracked this one myself.

To see all environment variables available add to the Execute shell field:

printenv

Console output will then show all the available vars.

Nanice answered 14/7, 2014 at 21:29 Comment(1)
You can also use the env command. But it's still not showing up for me..Kunzite
E
6

Please also have a look at: How can I access the last built revision according to jenkins?

The part with the env-vars url was really helpful:

Lastly, to see a less comprehensive list of available environment variables, you can also just go to this url: http://[your-jenkins-domain-and-port]/env-vars.html

Extinct answered 22/1, 2018 at 14:1 Comment(0)
F
0

Similarly you could just echo them out:

echo GIT_COMMIT %GIT_COMMIT% 
echo GIT_BRANCH %GIT_BRANCH%

enter image description here

Here's a quick Jenkins Git configuration tutorial on the Git environment variables topic that uses the Jenkins Git configuration described in the image.

Fortyfive answered 26/7, 2018 at 13:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.