• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • git-plugin
    • None

      It's been noted in other issues (JENKINS-35230) that the Git plugin does not export its environment variables when used with a pipeline job. In addition, the plugin does not set user.name and user.email, as it does in traditional jobs, meaning that any attempts to commit to the repository from within a pipeline fail with "tell me who you are".

      It would be useful to have the environment variables available, but even without them, the plugin should be able to set the Git config as it performs checkout.

          [JENKINS-43563] Git plugin does not set user in pipeline

          Mark Waite added a comment -

          Inserting an sh or bat step after the checkout and prior to the first command that performs a commit should be enough. Something like this:

          sh 'git config user.name Your.Name'
          sh 'git config user.email your.address@example.com'
          

          Those two commands will define git user name and git email address in that repository (and only in that repository).

          Mark Waite added a comment - Inserting an sh or bat step after the checkout and prior to the first command that performs a commit should be enough. Something like this: sh 'git config user.name Your.Name' sh 'git config user.email your.address@example.com' Those two commands will define git user name and git email address in that repository (and only in that repository).

          Lei JIANG added a comment -

          It that possible to prioritise this issue please. 

          Lei JIANG added a comment - It that possible to prioritise this issue please. 

          Mark Waite added a comment - - edited

          leijiang please use the workaround described in the comment prior to your request. Because there is an easy work around, this will not be investigated further by me.

          Mark Waite added a comment - - edited leijiang please use the workaround described in the comment prior to your request. Because there is an easy work around, this will not be investigated further by me.

          Sorry this is not acceptable.
          The documentation in https://plugins.jenkins.io/git clearly states that the plugin will do the user and email configuration. Do you know how much hours developers waste to find out that something that should work out of the box needs workarounds?
          We have pipelines with more then 10 git checkouts where updates get pushed, so the pipeline scripts gets totally ugly.

          Michael Düsterhus added a comment - Sorry this is not acceptable. The documentation in https://plugins.jenkins.io/git clearly states that the plugin will do the user and email configuration. Do you know how much hours developers waste to find out that something that should work out of the box needs workarounds? We have pipelines with more then 10 git checkouts where updates get pushed, so the pipeline scripts gets totally ugly.

          Daniel Beck added a comment -

          The documentation

          It's sourced from a wiki page linked in the sidebar, everyone with an account can edit it. Users frequently contribute to that, and the changes are of varying quality. I'm sure Mark would appreciate your help in improving the quality of the documentation.

          Daniel Beck added a comment - The documentation It's sourced from a wiki page linked in the sidebar, everyone with an account can edit it. Users frequently contribute to that, and the changes are of varying quality. I'm sure Mark would appreciate your help in improving the quality of the documentation.

          Mark Waite added a comment -

          reitzmichnicht I'm happy to receive a pull request with automated tests that show the problem and a code change that fixes the tests. Thanks for your interest in helping the Jenkins project!

          Mark Waite added a comment - reitzmichnicht I'm happy to receive a pull request with automated tests that show the problem and a code change that fixes the tests. Thanks for your interest in helping the Jenkins project!

          Adam Roberts added a comment -

          I have added a Warning on the https://wiki.jenkins.io/display/JENKINS/Git+Plugin page as I too wasted time trying to debug this issue.

          Adam Roberts added a comment - I have added a Warning on the https://wiki.jenkins.io/display/JENKINS/Git+Plugin page as I too wasted time trying to debug this issue.

          Is it possible to access these settings programmatically in the pipeline?

          Michael michael@wyraz.de added a comment - Is it possible to access these settings programmatically in the pipeline?

          Michael michael@wyraz.de added a comment - - edited

          Update: it is possible through the scm variable. So my workaround is:

          					def scmvars=steps.checkout(globals.scm)
          					if (scmvars.GIT_AUTHOR_NAME && scmvars.GIT_AUTHOR_EMAIL) {
          						steps.sh(script:"""
          							git config user.name '${scmvars.GIT_AUTHOR_NAME}'
          							git config user.email '${scmvars.GIT_AUTHOR_EMAIL}'
          							""")
          					}
          

          Michael michael@wyraz.de added a comment - - edited Update: it is possible through the scm variable. So my workaround is: def scmvars=steps.checkout(globals.scm) if (scmvars.GIT_AUTHOR_NAME && scmvars.GIT_AUTHOR_EMAIL) { steps.sh(script:""" git config user.name '${scmvars.GIT_AUTHOR_NAME}' git config user.email '${scmvars.GIT_AUTHOR_EMAIL}' """) }

          The workaround from above is not working though if only global git settings are used (not the per project behaviour). The according environment variables are not set if in that case.

          Konrad Windszus added a comment - The workaround from above is not working though if only global git settings are used (not the per project behaviour). The according environment variables are not set if in that case.

            Unassigned Unassigned
            chrylis Christopher Smith
            Votes:
            17 Vote for this issue
            Watchers:
            23 Start watching this issue

              Created:
              Updated: