詹金斯和Git - 如何抓取提交者的名字? [英] Jenkins and Git - how to grab a committer's name?
问题描述
我看到有许多GIT变量可以在jenkins中使用。我正在执行一项工作的Execute Shell步骤。
这些工作:
echo$ {GIT_BRANCH}
echo$ {GIT_URL}
echo$ {GIT_COMMIT}
$ c $
$ p $ echo $ {GIT_COMMITTER_EMAIL}
echo$ {GIT_COMMITTER_NAME}
echo$ {GIT_AUTHOR_EMAIL}
echo$ {GIT_AUTHOR_NAME}
echo$ {GIT_USER}
问题1:以上的变数不起作用?
这个作品:
git show --name-only
问题2:我为什么不能做
Foo = git show --name-only
然后在工作中使用Foo else,即发送给HipChat?
我看到有一个插件envInject。但是这是写入执行执行shell步骤的工作区中的文件,然后从该文件读取。这似乎有点矫枉过正,我想要做的事情。
问题3:envInject是我唯一的选择吗?
我不知道为什么有些变量是可用的,有些不是,但似乎你不是唯一存在这个问题的变量(参见 Jenkins的Git插件:如何设置env变量GIT_AUTHOR_EMAIL和GIT_COMMITTER_EMAIL?)。
使用例如 git show -s --pretty =%an
获取作者姓名并通过命令替换将其存储在变量中,如@MattKneiser所解释:
foo = $(git show -s --pretty =%an)
这个变量在Jenkins作业中的其他shell步骤中不可用,但可以将其保存到工作区中的文件中。
echofoo = \$ foo \> $ WORKSPACE / envvars
然后在另一个shell中输入该文件:
。 $ WORKSPACE / envvars
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
这篇关于詹金斯和Git - 如何抓取提交者的名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!