如何在Jenkins管道内使用GitHub提交消息和提交ID? [英] How to use GitHub commit message and commit id inside Jenkins pipeline?

查看:174
本文介绍了如何在Jenkins管道内使用GitHub提交消息和提交ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DevOps模型,在该模型中,我已经建立了用于代码构建和部署的管道. 在整个过程中,我要记录Git提交ID和该特定更改提交的提交消息.

I am using DevOps model, where i have built a pipeline for code build and deploy. In the entire process i want to log the Git commit id and commit message for that specific change commits.

@shruthibhaskar
shruthibhaskar committed just now 
1 parent 51132c4 commit aedd3dc56ab253419194762d72f2376aede66a19

并提交以下消息和说明

test commit 3

test commit desc 3

我如何在jenkins管道中访问这些commit值,在那里我已为SCM轮询配置了一个Webhook?

how do i access these values of commit inside my jenkins pipeline, where i have configured a webhook for SCM polling?

推荐答案

Jenkins git插件为每次构建都设置了一些环境变量.您可以在 git插件站点中找到它们的列表.在其中,它给出了 $ {GIT_COMMIT} 环境变量中当前提交的SHA.

Jenkins git plugin set some environment variables for every build. You can find the list of them in git plugin site. In which it gives the SHA of the current commit in ${GIT_COMMIT} environment variable.

您可以将SHA和git log一起使用以打印提交消息以及使用--pretty选项所需的任何其他详细信息.

You can use the SHA along with git log to print commit message and any other details you required with --pretty option.

git log --oneline -1 ${GIT_COMMIT} # prints SHA and title line
git log --format="medium" -1 ${GIT_COMMIT} # print commit, author, date, title & commit message

这篇关于如何在Jenkins管道内使用GitHub提交消息和提交ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆