gpt4 book ai didi

jenkins - 如何参数化 Jenkins 管道中复制工件的选择器

转载 作者:行者123 更新时间:2023-12-01 04:50:03 25 4
gpt4 key购买 nike

我们在 Jenkins 系统中大量使用管道作业,并且需要能够参数化 copyArtifacts使用 Build selector for Copy Artifact 的步骤作业参数。

首先我发现 - 而参数返回 String - copyArtifacts步骤需要 BuildSelector 的实例.

我找到了 BuildSelectorParameter.getSelectorFromXml将参数转换为 BuildSelector 实例的方法喜欢:

properties([parameters([
[$class: 'BuildSelectorParameter',
defaultSelector: upstream(fallbackToLastSuccessful: true),
description: '',
name: 'copyArtifactSelector']])
])

@NonCPS
static BuildSelector getSelectorFromParam(String xmlText) {
BuildSelectorParameter.getSelectorFromXml(xmlText)
}

node {
def selector = getSelectorFromParam(params.copyArtifactSelector)
copyArtifacts(
projectName: 'sourceJob',
selector: selector
)
}

但是我刚刚意识到 BuildSelector创建的不是 Serializable .因此,我现在得到了预期的异常:
hudson.plugins.copyartifact.TriggeredBuildSelectorCaused: java.io.NotSerializableException: hudson.plugins.copyartifact.TriggeredBuildSelector    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)    at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)    at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)

After that I tried to check how the copy artifact plugin deals with that - unfurtunately I couldn't find any clue in the source code. Maybe it only works by chance? The methods to create a BuildSelector do not seem to create any kind of serializable class.

But maybe someone already came accross this issue and has a hint?

Edit

What I found so far:

  • If I store the BuildSelector object in some variable it'll throw me the NotSerializableException.
  • However if I do not pass it to some variable first but do the call in the method call to copyArtifacts the NotSerializableException will not occur - at least not for now:

    node {
    copyArtifacts(
    projectName: 'sourceJob',
    selector: getSelectorFromParam(params.copyArtifactSelector)
    )
    }

  • 想法

    Copy Artifact 插件中是否有可能导致 NotSerializableException 的隐藏错误?发生异常 - 或者我错过了什么?



    使用我的 getSelectorFromParam 安全吗?方法像在更新的例子中完成的那样?如果不安全,是否有安全的解决方案?

最佳答案

在花了几个小时之后,我遇到了同样的问题,我发现了这一点,它对我来说非常有效。

的名称复制工件的构建选择器 这里的作业参数是 copyArtifactSelector,这里的上游作业名称是 sourceJob:

    copyArtifacts(projectName: 'sourceJob',
selector: [$class: 'ParameterizedBuildSelector',
parameterName: 'copyArtifactSelector'] );

注意:插件=“copyartifact@1.39.1”

编辑:
与此同时 - 使用 copyartifact V1.43 - 支持以下语法:
    copyArtifacts(projectName: 'sourceJob',
selector: buildParameter('copyArtifactSelector'));

关于jenkins - 如何参数化 Jenkins 管道中复制工件的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51767768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com