我正在设置私有GitHub仓库和Jenkins构建之间的Webhook集成。我使用Job DSL groovy脚本独占地配置作业(我可以考虑切换到另一个编程式作业配置机制,但是不接受任何要求我手动配置作业的答案)。我想根据构建状态设置提交状态上下文和一组自定义消息。
在Jenkins中嵌入的Job DSL API文档没有帮助,只给出了这个签名:
以下是我Job DSL的相关部分:
如果我删除整个
我不是Groovy程序员,也不太熟悉Jenkins的任何方面。我明白没有与我编写的DSL兼容的方法,但我不知道在哪里查找有效的方法签名。我不理解DSL如何映射到方法调用,以找到或甚至识别一个适当的方法和构建与其兼容的DSL。
在这一切之中,我很难理解buildStatus、commitStatus、completedStatus等之间的区别。这些东西是什么意思?
同时,我将DSL还原到没有任何buildStatus的版本,并尝试创建一个PR以查看是否会触发构建。但它没有。我检查了"GitHub Hook Log":
也许钩子日志不是查找的正确位置,但在调用
我最初在使用CloudBees Core Client Master版本2.204.3.7、修订版3时遇到了这些问题。升级到最新版本(2.235.2.3)没有帮助。
正在使用的插件版本:
Job DSL: 1.77
GHPRB: 1.42.1
如果还有其他相关的插件,请告诉我,我会添加它们。
我的问题总结:
1. 配置自定义状态消息以在GitHub中显示的正确语法是什么? 2. 我的配置除了轮询远程存储库忽略PR和打开新的PR不触发构建外,还有什么问题吗? 3. 还有其他地方可以查找这些内容的文档吗?或者其他资源可以帮助我学习我正在做的事情?
在Jenkins中嵌入的Job DSL API文档没有帮助,只给出了这个签名:
githubPullRequest(Closure closure)
,但没有告诉我如何构造合适的闭包。以下是我Job DSL的相关部分:
triggers {
githubPush()
githubPullRequest {
useGitHubHooks()
buildStatus {
completedStatus('SUCCESS', 'Build succeeded!')
completedStatus('FAILURE', 'Build failed. ')
completedStatus('ERROR', 'Build errored. This is probably a problem with Jenkins or related infrastructure and not an issue with your code changes.')
}
}
}
(...)
scm {
git {
remote {
github('privateorg/myrepo', 'ssh')
credentials('my-credential-id')
refspec('+refs/pull/*:refs/remotes/origin/pr/*')
}
branch('${sha1}')
}
}
这个错误如下:
ERROR: (build.groovy, line 8) No signature of method: javaposse.jobdsl.dsl.helpers.triggers.TriggerContext.buildStatus() is applicable for argument types:
(build$_run_closure1$_closure2$_closure10$_closure11) values:
[build$_run_closure1$_closure2$_closure10$_closure11@602572cb]
第8行是:
buildStatus {
如果我删除整个
buildStatus
块,那么Jenkins将接受脚本并成功创建作业。我的推送挂钩有效,但我的拉取请求挂钩无效。我不是Groovy程序员,也不太熟悉Jenkins的任何方面。我明白没有与我编写的DSL兼容的方法,但我不知道在哪里查找有效的方法签名。我不理解DSL如何映射到方法调用,以找到或甚至识别一个适当的方法和构建与其兼容的DSL。
通过谷歌搜索错误信息,我找到了一些在2016-2017年遇到类似问题的人:1, 2, 3。他们的问题似乎源自于Github Pull Request Builder插件作为核心捆绑插件的弃用及相应语法的更改。这使我发现了一种新的语法,可在此处找到:
triggers {
githubPush()
githubPullRequest {
useGitHubHooks()
extensions {
'org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus' {
buildStatus {
'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
message 'Build in progress...'
result 'PENDING'
}
'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
message 'Build succeeded! It is safe to merge ${ghprbSourceBranch} into ${ghprbTargetBranch}.'
result 'SUCCESS'
}
'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
message 'Build failed.'
result 'FAILURE'
}
'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
message 'Build errored. This is probably a problem with Jenkins or related infrastructure and not an issue with your code changes.'
result 'ERROR'
}
}
}
}
}
}
但这也没有帮助; 失败本质上是相同的:
ERROR: (build.groovy, line 9) No signature of method: javaposse.jobdsl.dsl.helpers.triggers.TriggerContext.org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus() is applicable for argument types:
(build$_run_closure1$_closure2$_closure10$_closure11$_closure12) values:
[build$_run_closure1$_closure2$_closure10$_closure11$_closure12@707221f0]
第9行是:
'org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus' {
在这一切之中,我很难理解buildStatus、commitStatus、completedStatus等之间的区别。这些东西是什么意思?
同时,我将DSL还原到没有任何buildStatus的版本,并尝试创建一个PR以查看是否会触发构建。但它没有。我检查了"GitHub Hook Log":
Started on Aug 4, 2020 6:16:47 PM
Started by event from 10.101.32.177 ⇒ https://my-jenkins-host.com/github-webhook/ on Tue Aug 04 18:16:47 UTC 2020
Using strategy: Default
[poll] Last Built Revision: Revision 91170fb44c40737a6410acfba820d6555a0475bb (refs/remotes/origin/dev)
using credential my-credential-id
> git --version # timeout=10
using GIT_ASKPASS to set credentials
> git ls-remote -h -- git@github.com:privateorg/myrepo.git # timeout=10
Found 64 remote heads on git@github.com:privateorg/myrepo.git
Ignoring refs/heads/branch1 as it doesn't match any of the configured refspecs
Ignoring refs/heads/branch2 as it doesn't match any of the configured refspecs
...
Ignoring refs/heads/branch64 as it doesn't match any of the configured refspecs
Done. Took 0.71 sec
No changes
也许钩子日志不是查找的正确位置,但在调用
git ls-remote
时使用-h
导致它只列出分支而不是PR。如果我在本地使用相同的命令但不带-h
,则会列出我确信与我的refspec匹配的PR。我最初在使用CloudBees Core Client Master版本2.204.3.7、修订版3时遇到了这些问题。升级到最新版本(2.235.2.3)没有帮助。
正在使用的插件版本:
Job DSL: 1.77
GHPRB: 1.42.1
如果还有其他相关的插件,请告诉我,我会添加它们。
我的问题总结:
1. 配置自定义状态消息以在GitHub中显示的正确语法是什么? 2. 我的配置除了轮询远程存储库忽略PR和打开新的PR不触发构建外,还有什么问题吗? 3. 还有其他地方可以查找这些内容的文档吗?或者其他资源可以帮助我学习我正在做的事情?