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

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

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


当前回答

好的,下面是如何设置Jenkins来设置GitHub构建状态。这里假设你已经有了Jenkins和GitHub插件,可以在每次推送时进行构建。

Go to GitHub, log in, go to Settings, Developer Settings, Personal access tokens and click on Generate new token. Check repo:status (I'm not sure this is necessary, but I did it, and it worked for me). Generate the token, copy it. Make sure the GitHub user you're going to use is a repository collaborator (for private repos) or is a member of a team with push and pull access (for organization repos) to the repositories you want to build. Go to your Jenkins server, log in. Manage Jenkins → Configure System Under GitHub Web Hook select Let Jenkins auto-manage hook URLs, then specify your GitHub username and the OAuth token you got in step 3. Verify that it works with the Test Credential button. Save the settings. Find the Jenkins job and add Set build status on GitHub commit to the post-build steps

就是这样。现在做一个测试构建,去GitHub存储库看看它是否工作。单击主存储库页面中的Branches查看构建状态。

你应该看到绿色的复选标记:

其他回答

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

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

还有这个插件,它会给你一个徽章的url,你可以在你的README中发布。Md,看起来像这样

https://wiki.jenkins-ci.org/display/JENKINS/Embeddable+Build+Status+Plugin

提交状态API允许你看到“回购状态API”。

自2013年4月26日起,你现在可以在你的GitHub回购分支页面上看到构建状态:

这意味着它是另一种方式,通过访问GitHub项目页面来查看这些状态,而不是只有Jenkins。

从2013年4月30日开始,提交状态的API端点已经扩展到允许分支和标记名称,以及提交sha。

编辑:

我不再使用这种方法,请使用其他答案之一。

更新:对于我们的具体情况,我最终做了什么:(上面的答案很棒-谢谢!)

因为我们的构建服务器不在互联网上,我们有一个脚本来发布构建状态到github中的gh-pages分支。

开始构建戳记失败 构建结束,戳记成功 项目在主项目之后运行,以发布结果——>构建状态、API文档、测试报告和测试覆盖率。

GitHub缓存图像,因此我们创建了.htaccess文件,该文件指示构建状态图像有一个短的缓存超时。

把这个和build-status镜像放在一起:

ExpiresByType image/png "access plus 2 minutes"

下面是构建脚本。发布到gh-page的目标是'——publish.site.dry.run'

在少于400行的配置中,我们有:

编译检查 单元和集成测试 测试报告 代码覆盖率报告 API文档 发布到Github

。。这个脚本可以在Jenkins内部或外部运行,这样:

开发人员可以在提交之前运行这个脚本,从而减少了错误构建影响其他构建的可能性。 故障很容易在本地重现。

结果:

项目主页有构建状态,每次构建后都会更新,还有最新的API文档、测试结果和测试覆盖率。

我所做的很简单:

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!\" }"