3

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!

Community
  • 1
  • 1
dstj
  • 4,800
  • 2
  • 39
  • 61

1 Answers1

5

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)
Slav
  • 27,057
  • 11
  • 80
  • 104
  • Thanks for your reply (btw, feel free to update the title if you know how to make it clearer, I didn`t ;)). I'm not sure I follow your last edit: in my test "diamond-join project", I have 4 jobs. All jobs can have different BuildNumber (because of failure, aborts, etc.), the PL_BUILD_NUMBER is only the build number of the pipeline's initial job and I manually pass it around all jobs, so most likely, PL_BUILD_NUMBER is *not* the BuildNumber of the jobs to copy artifacts from. I'll edit the question to better reflect that. – dstj Aug 27 '14 at 17:16
  • Well, you do need the `BUILD_NUMBER` of the job whose artifacts you want to copy. You could use "Last successful build" instead, if your pipeline is synchronous. Or if you are triggering your downstream jobs through Parameterized Trigger plugin, you can pass the `BUILD_NUMBER` downstream – Slav Aug 27 '14 at 17:22
  • If you want to Copy Artifacts **in** jobs `2` and `3`, you could use "Upstream build that triggered this job" selection. But you can't use that in job `4` (just like the guy found out in the question you are quoting). It all depends on how you trigger the downstream jobs and where do you need this. – Slav Aug 27 '14 at 17:27
  • I need job 4 to get artifacts *from* Jobs 2 *and* 3. Job 4 is triggered in a post build join-trigger from Job 1. – dstj Aug 27 '14 at 17:32
  • Well, you are in a pickle... I'd still recommend "Last successful build" selection. – Slav Aug 27 '14 at 17:41
  • 1
    @Slav: thank you for describing how the build selector works, I'd have had a hard time figuring it out all by myself! – Lvsti Nov 27 '14 at 20:57