我正试图从Freestyle Project转变为multibranch管道构建。我希望在将新容器推送到我的Quay.io存储库时触发我的Jenkinsfile。在Freestyle Project中,我能够使用Quay.io Trigger插件完成此任务。 转到Multibranch构建管道我发现了post,它描述了如何在dockerhub触发器上触发。我还使用了Jenkins Pipeline Syntax"向导"生成要添加到我的Jenkinsfile的代码:
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=
有没有人真的在Jenkins文件中使用它?
答案 0 :(得分:0)
答案:
如果在Jenkins文件中将存储库集合强制转换为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 Trigger插件中挖掘了source code。当前插件的设计并未考虑Jenkins Pipeline,因此it uses a Set位于存储库集合的构造函数中。
这是发生强制转换异常的地方,因为Groovy将字符串列表视为数组,无法自动将其转换为集合。
通过显式创建存储库列表作为集合,该插件可在Jenkinsfile
中配置。
希望这有帮助!