Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy build artifact between nodes using Jenkins pipeline

Tags:

I'm trying to move existing Jenkins build jobs to a single Jenkins 2 pipelines, and wondering if it's possible to copy files from one node to another within the build. My idea would be :

Node A (Windows)   Checkout scm   Execute ant build   Archive artifact (or whatever required action) Node B (Unix)   Checkout scm   Copy build artifact from node A --> is this possible ?   Execute ant build   Then followed by tests... 

I've tried to use the copy artifact step, but it didn't seem to work correctly, so I'm wondering if there's a way to copy files in the middle of the pipeline, or if I have to stay with the current build architecture (using copy artifact plugin, but with completely separate build jobs).

like image 248
Gilles QUERRET Avatar asked Jun 07 '16 19:06

Gilles QUERRET


People also ask

What is the use of copy artifact plugin in Jenkins?

The plugin lets you specify which build to copy artifacts from (e.g. the last successful/stable build, by build number, or by a build parameter). You can also control the copying process by filtering the files being copied, specifying a destination directory within the target project, etc.

Under which section is the copy artifacts option present in Jenkins?

Next you need to install the Copy Artifact plugin in the Manage Plugins section of Jenkins. Go to "[PROJECT-NAME]-Output" > configure and add a new build step. Because you have installed the Copy Artifact plugin you should see an option called 'copy artifacts from another project' in the drop down menu.


1 Answers

Yes, this is possible using the stash/unstash steps.

A tutorial about this can also be found in the Jenkins Blog (focused on parallel execution):

parallel (     "stream 1" : {                       node {                             unstash "binary"                                                       sh "sleep 20s"                             sh "echo hstream1"                        }                     },     "stream 2" : {                       node {                             unstash "binary"                            sh "echo hello2"                            sh "hashtag fail"                                                                               }                     }           ) 
like image 183
StephenKing Avatar answered Sep 28 '22 00:09

StephenKing