0
votes

i have a jenkins master running inside a container ... and i'm tyring to containerize my builds using Docker containers as Jenkins Slave (build agents), on a separete vm , to run my CI pipelines. This Docker container (build agents) will be created when the CI pipeline runs; . once the build is complete the Docker container will be destroyed. To achieve this:

  • i use docker plugin as following:

enter image description here

  • this my jenkinsfile code:

    node('docker') { 
      stage('Checkout Code') { 
          checkout scm  }
      stage('Build') {
        withMaven {
            sh 'mvn clean install' }
      }
    }

when i run my peline every thing is going right :

but the question is about the build results (.war)
are this archives transferred to the master workspace or destroyed with the container ?? if the second case then how can i recuperate the build results to jenkins master to pursue CI process ??

[INFO] Installing /home/jenkins/workspace/Build_pipeline_team/target/Teams.war to /home/jenkins/.m2/repository/teams/Teams/1.0-SNAPSHOT/Teams-1.0-SNAPSHOT.war
[INFO] Installing /home/jenkins/workspace/Build_pipeline_team/pom.xml to /home/jenkins/.m2/repository/teams/Teams/1.0-SNAPSHOT/Teams-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:12 min
[INFO] Finished at: 2017-11-15T03:40:13+00:00
[INFO] Final Memory: 21M/51M
[INFO] ------------------------------------------------------------------------
[jenkins-maven-event-spy] INFO generated /home/jenkins/workspace/Build_pipeline_team@tmp/withMaven673f8d6e/maven-spy-20171115-033800-6375412806014049683204.log
[Pipeline] }
[withMaven] artifactsPublisher - Archive artifact pom.xml under teams/Teams/1.0-SNAPSHOT/Teams-1.0-SNAPSHOT.pom
[withMaven] artifactsPublisher - Archive artifact target/Teams.war under teams/Teams/1.0-SNAPSHOT/Teams-1.0-SNAPSHOT.war
[withMaven] junitPublisher - Archive test results for Maven artifact teams:Teams:1.0-SNAPSHOT generated by maven-surefire-plugin:test (default-test): target/surefire-reports/*.xml
1

1 Answers

0
votes

When you encapsulate the stage inside a node, everything will run on that node. Thus the war will be destroyed with the container when the build finished.

You have several alternatives to keep the war.

The maven way is to deploy artifacts to a repository such as nexus.

Another Jenkins alternative is to stash the war on the slave once the build finishes and unstash it back on the master. This will effectively copy back the stashed files from the slave to the master node.