Jenkins and Git – how to grab a committer's name?

I am trying to get more GIT commit information into a HipChat room.

I see there are a number of GIT variables that can be used in jenkins. I am working in the Execute Shell step of a job.

  • Git Best Practice: How do you tag a revision “TESTED” or “REJECTED”
  • Git will not init/sync/update new submodules
  • New git repository error on first push
  • Advises on the gestion of a website via Git : Images and other big files
  • gitolite package doesn't create user
  • Stop Teamcity showing deleted branches
  • These work:

    echo "${GIT_BRANCH}"
    echo "${GIT_URL}"
    echo "${GIT_COMMIT}"

    These do not:

    echo "${GIT_COMMITTER_NAME}"
    echo "${GIT_AUTHOR_EMAIL}"
    echo "${GIT_AUTHOR_NAME}"   
    echo "${GIT_USER}"

    Question 1: how come the vars above don’t work?

    This works:

    git show --name-only

    Question 2: How come I cant do
    Foo = “git show –name-only”
    And use Foo else where in the job, ie- send to HipChat?

    I see there is a plugin envInject. But this is to write to a file in the workspace doing the execute shell step, then read from that file. This seems to be a bit overkill for what I am trying to do.

    Question 3: is the envInject my only option?

  • Set vim current working directory to the current project root or to the directory of the current file
  • Maven release via Hudson
  • git: having 2 push/pull repos in sync (or 1 push/pull and 1 pull in sync)
  • How to get --detect-branches to work with git-p4?
  • Escape comment character (#) in git commit message
  • Kdiff3 won't open with mergetool command
  • 3 Solutions collect form web for “Jenkins and Git – how to grab a committer's name?”

    I don’t know why some of the variables are available and some aren’t but it seems you’re not the only one with that problem (see e.g. Git plugin for Jenkins: How do I set env variables GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL?).

    Use e.g. git show -s --pretty=%an to obtain the author name and store it in a variable via command substitution as explained by @MattKneiser:

    foo=$(git show -s --pretty=%an)

    This variable won’t be available in other shell steps in your Jenkins job, but you could save it to a file in your workspace,

    echo "foo=\"$foo\"" > $WORKSPACE/envvars

    and later source that file in the other shell:

    . $WORKSPACE/envvars

    If you are using gerrit trigger plugin, you can get some info like:
    ${GERRIT_CHANGE_OWNER} or ${GERRIT_CHANGE_OWNER_NAME}, otherwise, try use the way @Matt mentioned, just create a simple shell script in your jenkins before you want to use this variable, and read it, inject it inot a file, later you can use it as a normal parameter.

    You need to explicitly execute that git command and put the output of it into a variable. In bash, this is called command substitution.

    foo=$(git show --name-only)
    Git Baby is a git and github fan, let's start git clone.