有没有办法在我项目的GitHub Readme.md上显示Jenkins构建状态?

我使用Jenkins运行持续集成构建。在每次提交之后,它确保在最终生成文档和发布包之前,所有内容都已编译,并执行单元和集成测试。

仍然存在无意中提交一些破坏构建的内容的风险。对于访问GitHub项目页面的用户来说,知道当前主程序处于该状态是很好的。


当前回答

我所做的很简单:

Install the Hudson Post Task Plugin Create a Personal Access Token here : https://github.com/settings/tokens Add a Post Task Plugin that always put success curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{ \"state\": \"success\", \"target_url\": \"${BUILD_URL}\", \"description\": \"The build has succeeded!\" }" Add a Post Task Plugin that will put failure if "marked build as failure" curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{ \"state\": \"failure\", \"target_url\": \"${BUILD_URL}\", \"description\": \"The build has failed!\" }" You can also add a call to pending at the beginning of tests curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{ \"state\": \"pending\", \"target_url\": \"${BUILD_URL}\", \"description\": \"The build is pending!\" }"

其他回答

加上这个答案,也加上这个答案,他们已经回答了这个问题,但没有给我们一个关于这个问题的正确的直觉

我的直觉是这样的:

We need to add status to our GitHub commit, this status is based upon the results of our Jenkins build. To do this we need to give Jenkins access to the GitHub API not to the repo, we do this through OAuth we can create the token going to the GH settings -> Developer settings -> Personal access tokens then for public GH repo just check repo:status, and for private repo check the whole repo section After creating your access token you need to add it to ur Jenkins server: Copy and paste the access token to the GitHub plugin section settings, under ur Jenkins configurations Create a GH server it defaults to api.github.com and add the access token as a secret text credentials. The last step is to add a post build settings when U create ur pipeline.

资源:

以下是YT视频的一个部分,他在其中介绍了上述步骤。 阅读OAuth

与此同时,Jenkins和GitHub的UI发生了一些变化,我花了一段时间才弄清楚如何正确配置Jenkins。这里的解释基于Jenkins版本2.121.1。

我还假设你已经配置了你的Jenkins作业由网络钩子或轮询触发。 以下是我为让它运转起来所采取的步骤:

配置Github:创建个人访问令牌与OAuth范围repo:状态 配置Jenkins:配置系统并添加OAuth秘密作为GitHub服务器-使用秘密文本作为身份验证方法,将OAuth秘密放在那里。 配置你的Jenkins Job:添加设置GitHub提交状态为Post-build action。将“状态结果”设置为默认消息和状态之一。 在GitHub上检查你的结果:检查你是否在GitHub提交上获得了构建状态和构建执行持续时间。

配置Github





配置詹金斯






配置Jenkins Job




结果

你现在会看到你的提交和分支的状态:

这个插件应该可以工作:https://wiki.jenkins-ci.org/display/JENKINS/Embeddable+Build+Status+Plugin

您应该能够将这样的徽章嵌入到README中。md文件:

我所做的很简单:

Install the Hudson Post Task Plugin Create a Personal Access Token here : https://github.com/settings/tokens Add a Post Task Plugin that always put success curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{ \"state\": \"success\", \"target_url\": \"${BUILD_URL}\", \"description\": \"The build has succeeded!\" }" Add a Post Task Plugin that will put failure if "marked build as failure" curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{ \"state\": \"failure\", \"target_url\": \"${BUILD_URL}\", \"description\": \"The build has failed!\" }" You can also add a call to pending at the beginning of tests curl -XPOST -H "Authorization: token OAUTH TOKEN" https://api.github.com/repos/:organization/:repos/statuses/$(git rev-parse HEAD) -d "{ \"state\": \"pending\", \"target_url\": \"${BUILD_URL}\", \"description\": \"The build is pending!\" }"

在README中添加以下行。md,并根据您的jenkins项目更改两个URL。

[![Build Status](https://jenkins../..project/lastBuild/buildStatus)](https://jenkins../..project/lastBuild/)