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.
These work:
echo "${GIT_BRANCH}"
echo "${GIT_URL}"
echo "${GIT_COMMIT}"
These do not:
echo "${GIT_COMMITTER_EMAIL}"
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?
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With