如何在 Jenkins 管道内使用 GitHub 提交消息和提交 ID?

Shr*_*kar 5 git github jenkins jenkins-pipeline

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

@shruthibhaskar
shruthibhaskar committed just now 
1 parent 51132c4 commit aedd3dc56ab253419194762d72f2376aede66a19
Run Code Online (Sandbox Code Playgroud)

并提交消息和描述如下

test commit 3

test commit desc 3
Run Code Online (Sandbox Code Playgroud)

我如何在我的 jenkins 管道中访问这些提交值,我在其中配置了一个用于 SCM 轮询的 webhook?

小智 6

git log --format=format:%s -1 (最新提交)

git log --format=format:%s -1 ${GIT_COMMIT} (具体提交)

git --no-pager show -s --format='%s' ${GIT_COMMIT}


Fid*_*del 5

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

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

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
Run Code Online (Sandbox Code Playgroud)