Alex028502
Alex028502

Reputation: 3814

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?

Upvotes: 4

Views: 1509

Answers (2)

Alex028502
Alex028502

Reputation: 3814

I figured out that there are variables with the numbers of triggered builds that I can use. To figure out the variable, I just printed all the environment variables with env and then found the right variable in the list.

Then I configured the copy artifacts plugin to use that build number.

enter image description here

I couldn't do it how @alex-o suggested, just getting the last build of the subjob, because I might have more than one job using the subjob at once, but if you don't have that problem, that might work for you.

Upvotes: 2

Alex O
Alex O

Reputation: 8164

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).

Upvotes: 1

Related Questions