Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git environment variables for use in executing Jenkins shell scripts

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

like image 351
user119680 Avatar asked Jul 14 '14 21:07

user119680


People also ask

How Jenkins use environment variables in shell script?

Jenkins Environment Variable is a global variable exposed through the env variable and used anywhere in the Jenkinsfile . Any value stored in the env variable gets stored as a String type. Environment Variables can be set either at the pipeline top level, at the specific stage level, or inside the script block.


1 Answers

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.

like image 112
user119680 Avatar answered Sep 25 '22 07:09

user119680