stash unstash to transfer data in Jenkins from a build container to the other node

+2 votes

I am having a Jenkins master running as a container on two virtual machine.

I am trying to run a build inside a docker container on a node so during the build process i had stashed my target folder to use it later on other node .In the job's log the stashing of folder was successful. when the build was finished the container is automatically destroyed then in the next step I unstashed that folder to achieve another stages in separate node but it didn't work..

I think unstash is not doing anything.

How do I transfer my target from the container to another node?

Below is the code written for pipeline:

node('docker') {
  stage('Checkout Code') {
      checkout scm
          }
  stage('Build') {
    withMaven( jdk: 'jdk_8', maven: 'maven 3') {
        mvn 'clean install'
        stash name: 'war', includes: 'x.war'
    }
  }

node('master') {
  stage('test') {
    withMaven( jdk: 'jdk_8', maven: 'maven 3') {
      unstash :	'war'
      sh 'mvn clean test'
    }
  }
 }
}

Can any one help me with this?

Thanks

May 1, 2018 in Jenkins by Atul
• 10,240 points

recategorized Sep 7, 2018 by Kalgi 33,346 views

5 answers to this question.

0 votes

I don't think that it is even getting stashed since the generated war should not be in the same directory where you executed mvn clean install.

I suppose the war to be under target.  It can be changed which includes: 'x.war' to includes: 'target/x.war' or go to the maven repository where the war is installed and stash the file from there:

withMaven( jdk: 'jdk_8', maven: 'maven 3') {
  mvn 'clean install'
  dir('<path to war>'){
      stash name: 'war', includes: 'x.war'
  }
}

I hope it will help you resolve your query.

answered May 1, 2018 by shubham
• 7,340 points

edited Sep 7, 2018 by Kalgi
0 votes
I agree with @Shubham, I highly doubt if the folder was stashed in the first place.
answered Dec 6, 2018 by Maverick
• 10,840 points
0 votes
Hey @Atul, Try keep your war under the target
answered Dec 6, 2018 by Haider
0 votes

Keep your war under target like this:

change includes: 'x.war' to includes: 'target/x.war'

answered Dec 6, 2018 by Keshav
0 votes
Since the container gets destroyed once the job is done , i guess we are not able to store the stashed file, may be try to do a sftp or scp to master server from docker node or we can start a container by passing arguments to mount a specific directory of master so that file will get stored in master file system
answered Dec 21, 2018 by anonymous

Related Questions In Jenkins

0 votes
1 answer

How do I pass value from my Fake # script to the host build server (Jenkins)

You can use the EnvInject plugin to pass environment ...READ MORE

answered Jul 11, 2018 in Jenkins by Kalgi
• 2,680 points
1,362 views
+1 vote
4 answers

Is there a way to change the Jenkins build number while building a job?

If you have access to the script ...READ MORE

answered May 7, 2019 in Jenkins by Atul
29,710 views
0 votes
3 answers

How to get the Maven Version of a project in Jenkins?

Here is a snippet from our Jenkins ...READ MORE

answered Oct 4, 2019 in Jenkins by Petr Doležal
23,188 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,715 views
0 votes
1 answer

Why is it displaying Jenkins build failure for Android app

I think you should try this. Try Uninstalling ...READ MORE

answered Apr 12, 2018 in Jenkins by shubham
• 7,340 points
1,775 views
0 votes
2 answers

Is possible for Jenkins to auto start and stop slave nodes?

Try Jenkins Plugin called as Slave SetupPlugin. This ...READ MORE

answered Aug 6, 2018 in Jenkins by Nilesh
• 7,060 points
6,845 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP