Git Additional Behaviors potential bug

28 views
Skip to first unread message

John Patrick

unread,
Aug 24, 2020, 7:29:32 PM8/24/20
to Jenkins Users
Might be a question for developers or a bug ticket.

I've got a multibranchPipelineJob project which runs a Jenkinsfile. The job executes as expected apart form one part.

If I select "Configure remote name" and change it to "origin1". When I do "sh 'git remote -v'". I see as expected;

[Pipeline] sh +
git remote -v
origin1 REPO (fetch)
origin1 REPO (push)
[Pipeline] sh

But If I do "Custom user name/e-mail address" and enter say "aName" and "aEm...@example.tld". When I do "sh 'git config --list'". I don't see user.name or user.email set, I just see;

[Pipeline] sh +
git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin1.url=REPO
remote.origin1.fetch=+refs/heads/*:refs/remotes/origin1/*
[Pipeline] sh

According to the documentation I should be seeing user.name and user.email set here. Just wondering if it's a bug, a bug with multibranch pipeline job, or I'm missing a step in my Jenkinsfile.

I'm using a Scripts Pipeline Jenkinsfile and am checking out the code using "checkout scm". And I've checked user.name and user.email before and after checkout.

Anyone else using multibranchPipelineJob and Custom name and email?

I've tested on v2.204.6, v2.222.4 and v.235.5, and the latest plugins which install on each of those versions.

Cheers,
John

Mark Waite

unread,
Aug 24, 2020, 7:56:17 PM8/24/20
to Jenkins Users
On Mon, Aug 24, 2020 at 5:29 PM John Patrick <nhoj.p...@gmail.com> wrote:
Might be a question for developers or a bug ticket.

I've got a multibranchPipelineJob project which runs a Jenkinsfile. The job executes as expected apart form one part.

If I select "Configure remote name" and change it to "origin1". When I do "sh 'git remote -v'". I see as expected;

[Pipeline] sh +
git remote -v
origin1 REPO (fetch)
origin1 REPO (push)
[Pipeline] sh

But If I do "Custom user name/e-mail address" and enter say "aName" and "aEm...@example.tld". When I do "sh 'git config --list'". I don't see user.name or user.email set, I just see;

[Pipeline] sh +
git config --list
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin1.url=REPO
remote.origin1.fetch=+refs/heads/*:refs/remotes/origin1/*
[Pipeline] sh

According to the documentation I should be seeing user.name and user.email set here. Just wondering if it's a bug, a bug with multibranch pipeline job, or I'm missing a step in my Jenkinsfile.


It is a bug in the documentation.  The documentation say one thing (sets config) while the code does something better (sets the environment variable GIT_COMMITTER_NAME and GIT_AUTHOR_NAME).  Documentation fix was merged today and should be visible within the next 24 hours at https://plugins.jenkins.io/git/#custom-user-name-e-mail-address

Mark Waite
 

John Patrick

unread,
Aug 25, 2020, 5:44:08 AM8/25/20
to jenkins...@googlegroups.com
Thanks for the reply, I can see the documentation talking about
GIT_COMMITTER_NAME and GIT_AUTHOR_NAME. Might seem a silly question
but how should I be accessing these environment variables from a
Jenkinsfile?

As I can echo BUILD_ID but not GIT_COMMITTER_NAME, e.g.

sh ' echo "BUILD_ID=${BUILD_ID}"'

give me;
[Pipeline] sh
+ echo BUILD_ID=22
BUILD_ID=22

but;
sh ' echo "GIT_COMMITTER_NAME=${GIT_COMMITTER_NAME}"'

give me;
[Pipeline] sh (hide)
+ echo GIT_COMMITTER_NAME=
GIT_COMMITTER_NAME=

I've tried ${env.GIT_COMMITTER_NAME} but that give "bad substitution"

I've tried;
sh ' echo "GIT_COMMITTER_NAME="' + GIT_COMMITTER_NAME

But that gives;
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property:
GIT_COMMITTER_NAME for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)

Do I have to wait for another jenkins release as your reply implied I
didn't as it was just a documentation issue and I was using the
wrong...

Or am I simply using the wrong syntax to access these environment
variables or missed some setup for the Jenkinsfile.

cheers,
John

>
> Mark Waite
>
>
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtGUPhbQd0O%3D%2B9TYU-Vy5jr7QqquMQWu2vorgX15MG8kjw%40mail.gmail.com.

John Patrick

unread,
Aug 25, 2020, 6:22:38 PM8/25/20
to jenkins...@googlegroups.com
So adding sh 'printenv' I don't see any GIT_ environment variables and
in the config.xml I've got it set as;

<jenkins.plugins.git.traits.UserIdentityTrait>
<extension class="hudson.plugins.git.extensions.impl.UserIdentity">
<name>aName</name>
<email>aEm...@example.tld</email>
</extension>
</jenkins.plugins.git.traits.UserIdentityTrait>

Anything else I should check, or anything else I need to configure to
get this working?

John

Mark Waite

unread,
Aug 25, 2020, 6:53:04 PM8/25/20
to Jenkins Users
It looks as though the environment variables that the git plugin is trying to set are not visible to later shell steps.  See  https://issues.jenkins-ci.org/browse/JENKINS-46052 for a work around using a shell command to define the user name and email address for the git committer.

John Patrick

unread,
Aug 25, 2020, 7:14:06 PM8/25/20
to jenkins...@googlegroups.com
Okay so it does look like a bug then ,raised 3 years ago and it's not
just me doing something stupid with my setup, configuration or
Jenkinsfile.

I was already doing the hardcoded workaround in the Jenkinsfile, but
then spotted the "Custom user name/e-mail address" option so wanted to
switch to that so it was no longer hard coded in the Jenkinsfile but
controlled by the Jenkins job.

I was even fine with having to add this to each Jenkinsfile to work
around it not setting local git config.

sh '''
git config user.email "${GIT_COMMITTER_EMAIL}"
git config user.name "${GIT_COMMITTER_NAME}"
'''

John
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtHCgPG92K1saFtAxEh7yrXjvKZd_baPOcgXsDkTzeXNpA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages