scala - How do I get the last commit programmatically in Java code? Jenkins / sbt
问题描述
I started writing a little tool that basically can do something (ex. compile or test code) and then send an email if it fails.
https://github.com/JohnReedLOL/EmailTestingBot
I want to add a feature where this tool can programmatically look at the last commit in the working directory, look at the author of the commit, extract their email, and then email that person whether their commit resulted in a pass or a failure.
For example, I want it to do something like: Git: See my last commit
Where the email basically says:
Subject: Test Results
Message: All your tests passed in dev for commit 0e39756383662573.
Does Jenkins provide this functionality already? I want to make my setup email the person who put in the most recent commit.
Also, is there a way I can obtain the email of the author of the most recent commit programmatically (ex. perhaps with http://www.eclipse.org/jgit/ or http://javagit.sourceforge.net )?
I don't really care how I get email notifications - I just want them and I can't use TravisCI.
解决方案
我将尝试部分给出解决方案。
第 1 部分:是的,您可以从Jenkins Link 运行 ShellScript(Shell Commands) 。
第 2 部分
如何从 GitCommit 获取电子邮件 ID 和其他东西。对于该Jenkins服务器应该在构建服务器中安装 git 命令。创建一个conf文件ex。/conf/reference
其中有
app {
git {
commit = "CURRENT_COMMIT"
repo = "CURRENT_REPO"
timestamp = "CURRENT_TIMESTAMP"
emailId = "EMAIL_ID"
}
}
当你的构建运行命令时
sed -i'' "s/CURRENT_COMMIT/$(git rev-parse HEAD)/g" conf/reference.conf
sed -i'' "s^CURRENT_REPO^$(git config --get remote.origin.url)^g" conf/reference.conf
sed -i'' "s/CURRENT_TIMESTAMP/$(git show -s --format=%ci HEAD)/g" conf/reference.conf
sed -i'' "s/EMAIL_ID/git --no-pager show -s --format='%an <%ae>' CURRENT_COMMIT/g" conf/reference.conf
上面的代码会将值放入reference.conf
. 现在您可以使用它来获取信息并发送邮件。据我所知,Jenkins 提供了发送电子邮件的能力。詹金斯处理环境变量而不是将其放入reference.conf
您可以将其放入环境变量并使用环境变量发送邮件。
仅供参考:我没有测试过这段代码,但据我记得在 Jenkins 工作,我们曾经通过这种方式发送电子邮件。
#快乐编码
推荐阅读
- kubernetes - 如何捕获每秒查询或微服务调用延迟?(没有 istio 或其他基于 envoy 的工具)
- html - 字体大小随html中的刷新而变化
- cfml - 我正在检查 Session.cart 是否已定义,如果未定义则定义它
- firebase - MissingPluginException(No implementation found for method DocumentReference) on Send data to firestore from flutter isolate
- stackexchange-api - 如何获得多个帖子的接受答案数量?
- python - con.commit 上的 Python 无效语法错误
- python - 如何使用 apply() 从另一列填充一列
- linux - 使用 grep 或 awk 计算准确的单词
- javascript - 使用 gsheet api 和 javascript 更新范围内的特定单元格
- python - Python Pip 本地下载