Docker容器为Jenkins Slave(构建代理)

时间:2017-11-15 14:20:33

标签: docker jenkins build continuous-integration devops

我有一个在容器内运行的jenkins主人...... 并且我正在使用Docker容器将我的构建容器化为Jenkins Slave(构建代理),在separete vm 上,以运行我的CI管道。 当CI管道运行时,将创建此Docker容器(构建代理);  。一旦构建完成,Docker容器将被销毁。 为此:

  • 我使用docker插件如下:

enter image description here

  • 这是我的jenkinsfile代码:



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




当我运行我的peline时,每件事情都是正确的:

但问题是关于构建结果(.war)
这些档案是转移到主工作区还是用容器销毁? 如果第二种情况那么我怎样才能将构建结果恢复到jenkins master来追求CI过程?



[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 个答案:

答案 0 :(得分:0)

将阶段封装在节点内时,一切都将在该节点上运行。因此,当构建完成时,战争将被容器破坏。

你有几种选择来保持战争。

maven方式是将工件部署到诸如nexus之类的目录。

Anothe jenkins的另一种选择是在构建完成后将战争存放在奴隶身上并将其重新放回主人身上。这将有效地将存储的文件从从站复制回主节点。