Search code examples
jenkinsjenkins-plugins

jenkins trying to copyArtifacts from a build that I trigger


I have installed the copyArtifacts plugin and created two freestyle jobs: experiment-main and experiment-1

experiment-1 just creates a file called artifact.txt with the build # in it, and archives it.

experiment-main triggers experiment-1 and then tries to copy the artifact like this:

enter image description here

but this is the result:

Running as SYSTEM
Building on master in workspace /var/lib/jenkins/workspace/experiment-main
Waiting for the completion of experiment-1
experiment-1 #4 started.
experiment-1 #4 completed. Result was SUCCESS
Build step 'Trigger/call builds on other projects' changed build result to SUCCESS
ERROR: Unable to find a build for artifact copy from: experiment-1
Finished: FAILURE

which isn't what I expected (or at least what I was hoping for)

I hoped it would find the experiment-1 build that was downstream from the current build.

Any ideas?


Solution

  • Yes, this is unexpected behavior indeed. The reason why this won't work is hidden in the help text of the "Upstream Project Name" input field:

    Downstream builds are found using fingerprints of files. That is, a build that is triggered from a build isn't always considered downstream, but you need to fingerprint files used in builds to let Jenkins track them.

    So, the Copy-Artifact plugin relies on fingerprint data to determine job ancestry. For that reason, you can not use the "Downstream build of..." feature using the current job as a parent: fingerprints are recorded in a post-build step, so an ongoing build of example-master does not have any fingerprints associated to it by the time it is looking for a matching build of experiment-1.

    It is possible to modify fingerprint information at build run-time (e.g., via Groovy), but then, it's probably best to avoid the Copy-Artifact plugin entirely and to implement the whole procedure in Groovy right away.

    Your best bet is probably to refer to example-1 via "Last successful build" and to ensure that this is the build that you triggered before (usually this will be correct, but depending on your setup there can be race conditions).