Jenkins Pipeline 无法触发具有 Maven 存储库构件的参数化作业。

huangapple go评论93阅读模式
英文:

Jenkins Pipeline unable to trigger a parameterized job which has a Maven Repository Artifact

问题

尝试触发具有Maven存储库工件类型参数的本地作业时,由于工作流支持未正确映射到VersionParameterValue类,作业触发失败。查看存储库连接器类中的代码,它尝试从冒号分隔的字符串实例化。

[VersionParameterValue@[name=deploy_number, groupid=com/****/database, artifactid=DB_xya, propertyName=deploy_number, version=1.2.3]]
[Pipeline] build (Building jobname)
Scheduling project: jobname
参数'deploy_number'的类型与jobname期望的类型不符。转换为Maven存储库工件。
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

java.lang.ArrayIndexOutOfBoundsException: 1
	at org.jvnet.hudson.plugins.repositoryconnector.VersionParameterDefinition.createValue(VersionParameterDefinition.java:140)
	at org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStepExecution.completeDefaultParameters(BuildTriggerStepExecution.java:193)
	at org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStepExecution.start(BuildTriggerStepExecution.java:101)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:286)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
...
在github中的源代码显示如下:

```java
@Override
public ParameterValue createValue(String input) {
    final String[] tokens = input.split(":");
    return new VersionParameterValue(tokens[0], tokens[1], tokens[2], tokens[3]);
}

希望这对您有所帮助。

<details>
<summary>英文:</summary>

When trying to trigger a local job which has a parameter type of Maven Repository Artifact the job fails to trigger due to the workflow support not correctly mapping to the VersionParameterValue class. Looking at the code in the repository-connector class its trying to instantiate from a colon separated string.

[VersionParameterValue@[name=deploy_number, groupid=com/****/database, artifactid=DB_xya, propertyName=deploy_number, version=1.2.3]]
[Pipeline] build (Building jobname)
Scheduling project: jobname
The parameter 'deploy_number' did not have the type expected by jobname. Converting to Maven Repository Artifact.
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

java.lang.ArrayIndexOutOfBoundsException: 1
	at org.jvnet.hudson.plugins.repositoryconnector.VersionParameterDefinition.createValue(VersionParameterDefinition.java:140)
	at org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStepExecution.completeDefaultParameters(BuildTriggerStepExecution.java:193)
	at org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStepExecution.start(BuildTriggerStepExecution.java:101)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:286)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
	at WorkflowScript.run(WorkflowScript:22)

We are using the jenkins 2.222.3 and build step 2.13, all required dependencies met. Running the job on its own works without issue. Looking for clues/workarounds

Which shows us from source in git hub

    @Override
    public ParameterValue createValue(String input) {
    	final String[] tokens = input.split(&quot;:&quot;);
        return new VersionParameterValue(tokens[0], tokens[1], tokens[2], tokens[3]);
    }

答案1

得分: 3

Yes, ran into the same issue and resolved in pipeline build job by constructing following:

string(name: 'ARTIFACT_PARAM_ID', value: "<groupId>:<artifactId>:ARTIFACT_PARAM_ID:${pomVersion}")

In the above:

  • ARTIFACT_PARAM_ID - 是我们尝试触发的作业中参数的名称
  • ${pomVersion} 是我们在管道中早些时候设置的环境变量,您可以将其替换为要传递的版本
  • <groupId> 将其替换为工件的组ID(我们选择它与我们尝试触发的作业中参数相同)
  • <artifactId> - 将其替换为工件的artifact ID(我们选择它与我们尝试触发的作业中参数相同)
英文:

Yes, ran into the same issue and resolved in pipeline build job by constructing following

string(name:&#39;ARTIFACT_PARAM_ID&#39;, value: &quot;&lt;groupId&gt;:&lt;artifactId&gt;:ARTIFACT_PARAM_ID:${pomVersion}&quot;)

In the above

  • ARTIFACT_PARAM_ID - is the name of the parameter in the job we are trying to trigger
  • ${pomVersion} is the environment variable we set earlier in pipeline, you can replace this with the version you want to pass a parameter
  • &lt;groupId&gt; replace this with group id of the artifact (we chose it to be same as what's in the parameter in the job we are trying to trigger)
  • &lt;artifactId&gt; - replace this with artifact id (we chose it to be same as what's in the parameter in the job we are trying to trigger)

huangapple
  • 本文由 发表于 2020年8月11日 03:55:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/63347139.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定