我正在尝试从Jenkins作业设置github状态。Jenkins返回一个
[Set GitHub commit status (universal)] SUCCESS on repos [] (sha:9892fbd) with context:ci/jenkins/tests
...但是当我稍后使用REST API查询它时,未设置状态。
这是一个很棒的代码:
def getCommitHash() {
sh(script: """
git rev-parse HEAD
""", returnStdout: true).trim()
}
def setCountTestLocation(String location) {
url = "https://<internal github>/<org>/<repo>"
commitHash = getCommitHash()
print(url)
print(commitHash)
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: url],
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/jenkins/tests"],
statusBackrefSource: [$class: "ManuallyEnteredBackrefSource", backref: location],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
commitShaSource: [$class: "ManuallyEnteredShaSource", sha: commitHash],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: "Tests here!", state: "SUCCESS", location: location]] ]
]);
}
3条答案
按热度按时间chhqkbe11#
如果您没有在全局Jenkins配置下设置“GitHub Server”配置,则可能会发生此问题:
管理Jenkins -〉配置系统-〉GitHub
您可以在GitHub插件文档的“自动模式”部分找到有关如何设置服务器配置的更多详细信息:
https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin#GitHubPlugin-AutomaticMode%28Jenkinsmanageshooksforjobsbyitself%29
yh2wf1be2#
在经历了同样的问题和插件的痛苦之后,这里有一个修复程序,不是针对这个特定的插件,而是一个不需要插件但仍然可以解决问题的变通方案,使用
curl
。您可以在管道中添加以下内容:其中,
GITHUB_API_URL
通常是这样构造的,例如在environment
指令中:可以从
Jenkins -> Credentials
创建和获取credentialsId
1tu0hz3e3#
您的存储库尚未更新,因为似乎未正确设置存储库。
插件仍然报告成功,因为它正确地完成了运行,但存储库列表是空的,如您的消息
SUCCESS on repos []
所示。