gitjenkinsgitblit

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.


Solution

  • 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}" />
    </target>