我正在尝试从Freestyle项目过渡到多分支管道构建。我希望将新容器推送到Quay.io存储库时触发Jenkinsfile。在Freestyle项目中,我可以使用Quay.io触发插件来完成此操作。
转到多分支构建管道,我找到了这个post,它描述了如何在dockerhub触发器上触发。我还使用了 Jenkins 管道语法“向导”来生成要添加到我的 Jenkins 文件中的代码:
properties([[$class: 'ScannerJobProperty', doNotScan: false], [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false], [$class: 'ThrottleJobProperty', categories: [], limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0, maxConcurrentTotal: 0, paramsToUseForLimit: '', throttleEnabled: false, throttleOption: 'project'], pipelineTriggers([[$class: 'QuayIoTrigger', repositories: ['hostedsparkbots/janitorbot-timer', 'hostedsparkbots/janitorbot', 'hostedsparkbots/sparky']]])])
在上述情况下,当我扫描github存储库时,从jenkins控制台获取了回溯的墙:
java.lang.IllegalArgumentException: java.lang.ClassCastException@712ddbf9
at sun.reflect.GeneratedMethodAccessor4447.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jenkinsci.plugins.structs.describable.Setter$1.set(Setter.java:33)
at org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:338)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:261)
Caused: java.lang.IllegalArgumentException: Could not instantiate {repositories=[hostedsparkbots/janitorbot-timer, hostedsparkbots/janitorbot, hostedsparkbots/sparky]} for QuayIoTrigger(repositories?: String[])
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:264)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:380)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:461)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:365)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:318)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:259)
Caused: java.lang.IllegalArgumentException: Could not instantiate {triggers=[{$class=QuayIoTrigger, repositories=
有人实际上在Jenkinsfile中工作吗?
最佳答案
答案:
如果您在Jenkinsfile中将存储库集合转换为java.util.Set
,则可以正常工作。使用上面的列表,您需要执行以下操作:
#!groovy
@import java.util.Set // this may not be required?
properties([
pipelineTriggers([[
$class: 'QuayIoTrigger',
repositories: (['hostedsparkbots/janitorbot-timer',
'hostedsparkbots/janitorbot',
'hostedsparkbots/sparky'] as Set)
]])
])
的背景:
我一直在努力想办法解决这个问题,但最终还是在Quay.io触发插件中浏览了source code。当前插件的设计并未考虑到Jenkins Pipeline,因此在存储库集合的构造函数中为it uses a Set。
这是发生强制转换异常的地方,因为Groovy将字符串列表视为数组,无法自动将其强制转换为Set。
通过显式地将存储库列表创建为Set,可以在
Jenkinsfile
中配置插件。希望这可以帮助!
关于docker - Jenkinsfile从quay.io触发插件触发作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46552354/