Docker containers as Jenkins Slave build agents

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

Can anyone help me with this query?

Thanks
Jun 16, 2018 in Docker by Atul
• 10,240 points
710 views

1 answer to this question.

0 votes

When you encapsulate the stage inside a node, everything will run on that node. Thus the war will ne 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 repisitory such as nexus.

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

answered Jun 16, 2018 by Atul
• 10,240 points

Related Questions In Docker

0 votes
1 answer

Build a container in Jenkins via "docker pipeline plugin"

In order to create a Docker image, ...READ MORE

answered Jul 9 in Docker by Sirajul
• 30,540 points
1,320 views
0 votes
1 answer

build an J2EE application with docker

I would suggest you to use volume ...READ MORE

answered May 1, 2018 in Docker by shubham
• 6,890 points
46 views
+1 vote
2 answers

How to run docker containers on different machines

You can use labels and selectors for ...READ MORE

answered Oct 23, 2018 in Docker by Laila
87 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
181 views
0 votes
1 answer
+1 vote
5 answers

Set containers timezones by using docker compose.

version "2" services: serviceA: ...READ MORE

answered Jul 8, 2018 in Docker by Atul
• 10,240 points
2,884 views
+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,110 points

edited Oct 16, 2018 by lina 4,831 views