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

Apr 30, 2018 in Jenkins by Atul
• 10,240 points

recategorized Sep 7, 2018 by Kalgi 5,529 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
• 6,890 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,040 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 20, 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,620 points
78 views
+1 vote
4 answers
0 votes
2 answers

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

Since the groovy script is a bit complex ...READ MORE

answered Jul 31 in Jenkins by Sirajul
• 18,490 points
643 views
0 votes
1 answer
0 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
• 56,520 points
132 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
• 6,890 points
221 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
• 6,900 points
730 views