我正在尝试从一个自由式项目转移到一个多分支管道构建。当一个新容器被推送到我的Quay.io存储库时,我希望我的Jenkinsfile触发。在自由式项目中,我可以通过Quay.io触发器插件来完成这个任务。移到多分支构建管道,我找到了这个帖子,它描述了如何在dockerhub触发器上触发。我还使用Jenkins管道语法“向导”生成要添加到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=有人把这个放在Jenkinsfile里吗?
发布于 2018-02-14 16:51:10
答案是:
如果您在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触发器插件中挖掘了Quay.io。当前插件的设计没有考虑到Jenkins管道,所以在存储库集合的构造函数中使用它使用一组。
这就是发生强制转换异常的地方,因为Groovy将字符串列表作为数组来处理,因此无法自动将其转换为一个集合。
通过显式地将存储库列表创建为一个集合,插件在Jenkinsfile中是可配置的。
希望这能有所帮助!
https://stackoverflow.com/questions/46552354
复制相似问题