How to determine the user who pushed to a remote repo in git using jenkins git plugin?

I need to find the git username/email of a person who is pushing changes, consisting of different commits by different users, to a remote repository.

The push triggers a Post-Receive hook via gitblit which triggers a jenkins job, and is using a non user specific SSH authentication.

  • Git Fatal Error: info/refs not found
  • Ignore specific commit but stay in head
  • Finding diff between two git repositories
  • What is the difference between “Already up-to-date.” and “Current branch master is up to date.”
  • How does SVN 1.8 merging compare with DVCS like Git & Mercurial?
  • Can't push github project to azure with git
  • How do I swap the order of two parents of a Git commit?
  • Deploy only specified files to AWS Elastic Beanstalk
  • how to know the depth of a git's shallow clone?
  • How to setup Continuous Integration in Visual Studio Online with Git and Nunit
  • Revert to an old commit in Bitbucket
  • git clone from GitHub RPC failed; result=56, HTTP code
  • 2 Solutions collect form web for “How to determine the user who pushed to a remote repo in git using jenkins git plugin?”

    Jenkins does not provide an easy way to accomplish that. I had a similar problem and it took me some time to find a suitable solution.

    I ended up using a combination of the Environmental Variables of Git Plugin and git log.

    Git Plugin offers two environmental variables:

    GIT_COMMIT – SHA of the current

    GIT_PREVIOUS_COMMIT – SHA of the previous built commit from the same
    branch (the current SHA on first build in branch)

    which you get every time your git Web Hook triggers the Jenkins job.

    On the other hand, git log provides the means to get the author name and author email using the format command option.

    Therefore, combining those two options you can get the author name and email of each commit between your previous commit which triggered the Jenkins job : GIT_PREVIOUS_COMMIT and the current commit : GIT_COMMIT using the git log command below:

    git log $GIT_PREVIOUS_COMMIT..$GIT_COMMIT --pretty=format:%an/%ae

    in an Executed Shell in your Jenkins Job. Please make sure that you are in root of your git project.

    I had to

    1. define a gitblit user and use it for pushing the changes.
    2. change my jenkins job to a parameterized one and define a parameter for the username (myuser).
    3. add the username in my hook


    def triggerUrl = jenkinsUrl + "/job/" + jenkinsJob + "/buildWithParameters?token=" + jenkinsToken + "&myuser=" + user.getName()
    new URL(triggerUrl).getText()

    myuser is now an enviroment variable, here as an example in an ant script :

    <property environment="env" />
    <target name="xx" description="xx">
        <echo message="${env.myuser}" />
    Git Baby is a git and github fan, let's start git clone.