Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy artifacts in a "diamond-join" Jenkins build pipeline?

Is there any documentation/examples on the Copy Artifacts Plugin, namely the "Specified by a build parameter" option?

I'm trying to do a "join-diamond" pipeline such as in this SO question and can't figure out what to put in the Parameter Name option of the "Copy artifacts from another project" build step to get my artifacts copied properly.

enter image description here

All my jobs have a PL_BUILD_NUMBER parameter and I'd like to use it to select which build to copy the artifacts from.

This mailing list post says the parameter must be an XML. So I tried this :

BUILD_SELECTOR=<SpecificBuildSelector><buildNumber>$PL_BUILD_NUMBER</buildNumber></SpecificBuildSelector>

but it did not work. I get this exception in the log:

java.lang.NullPointerException
    at java.io.StringReader.<init>(Unknown Source)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1035)
    at hudson.plugins.copyartifact.BuildSelectorParameter.getSelectorFromXml(BuildSelectorParameter.java:80)
    at hudson.plugins.copyartifact.ParameterizedBuildSelector.getBuild(ParameterizedBuildSelector.java:52)
    at hudson.plugins.copyartifact.CopyArtifact.perform(CopyArtifact.java:280)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:772)
    at hudson.model.Build$BuildExecution.build(Build.java:199)
    at hudson.model.Build$BuildExecution.doRun(Build.java:160)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:535)
    at hudson.model.Run.execute(Run.java:1740)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:233)

What should I put?

There's also the "This build is parametrized --> Build selector for Copy Artifact" that I don't know if I should use it...

Thanks!

like image 997
dstj Avatar asked Dec 02 '25 16:12

dstj


1 Answers

You are mixing Specified by a build parameter and Specific build. It's not clear which one you are asking about.

For Specified by a build parameter, you need to configure in two places:

  • Under "This build is parameterized", select "Build selector for Copy Artifact"
  • The Name of this parameter is what we will give to Copy Artifact build step later.
  • From the UI perspective, user will be prompted with a build selector interface (which allows all types of selections: last build, specific build, latest promoted, etc, etc).
  • On the "Copy Artifact" build step, under "Which build", select "Specified by a build parameter".
  • It will display another field called "Parameter Name" (with default being BUILD_SELECTOR).
  • That is the Name of the "Build selector for Copy Artifact" parameter that we created earlier.
  • Since default is BUILD_SELECTOR, if you called your parameter BUILD_SELECTOR as well, you don't need to change anything.

The value of BUILD_SELECTOR parameter will change greatly based on what you select at parameter screen just before build. You can see its possible values by printing the value of the parameter as a test (echo %BUILD_SELECTOR% on Windows, echo $BUILD_SELECTOR on *nix) and then manually running the build and trying different selectors.

Specifically, the value of:
<SpecificBuildSelector><buildNumber>123</buildNumber></SpecificBuildSelector>
will be used when the user selects Specific build on the parameter screen, and enters value 123

If you need to set this parameter value from outside the job (for example from a script or Parameterized Trigger plugin) you would need to follow this particular structure, depending on the type of the selection you want.

Edit: After re-reading your question and your actual requirement (which is not what the question title is)

In your case, you don't need "Build selector for Copy Artifact" parameter. You just need:

  • Copy Artifacts build step
  • Enter Project name to copy from
  • Under Which build, select Specific build
  • Under Build number, type $PL_BUILD_NUMBER (which you say you already have in the job)
like image 50
Slav Avatar answered Dec 05 '25 20:12

Slav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!