简体   繁体   English

了解Jenkinsfile针对Docker代理的步骤

[英]Understanding Jenkinsfile's steps for Docker agent

I have Jenkinsfile with the following steps: 我有Jenkinsfile,执行以下步骤:

stage('build') {
      agent {
           docker {
               image 'maven:3-alpine'
               args '-v /ec2-user/.m2:/root/.m2'
           }
      }
      steps {
        git(url: 'https://github.com/user/project.git', branch: 'master')
        sh 'cp /home/application-prod.properties src/main/resources'
        sh 'mvn clean install'
      }
    }

According to docs, Jenkins should Execute the steps in this stage in a newly created container using this image. 根据文档,Jenkins应该使用此图像在新创建的容器中执行此阶段的步骤。

If that is true, then why the second step's sh command is executed successfully? 如果是这样,那么为什么第二步的sh命令成功执行? How can it access the file on the Jenkins host? 它如何访问Jenkins主机上的文件?

To me, it looks like the commands are executed on the Jenkins host. 在我看来,这些命令似乎是在Jenkins主机上执行的。 Then why mvn clean install works fine? 那为什么mvn clean install可以正常工作呢? Jenkins host doesn't have Maven installed. Jenkins主机未安装Maven。

Because it is the usual case that you want to access the contents of your workspace, Jenkins automatically mounts it as a volume into the container. 因为通常是要访问工作空间的内容,因此Jenkins会将其作为卷自动安装到容器中。 Otherwise, in probably 99% of all jobs, one would have to specify that the checked out repo should be mounted into the container. 否则,在大约所有作业的99%中,必须指定将检出的仓库安装到容器中。

You should be able to see the -v parameters in the output of the build when it issues the docker run command. 发出docker run命令时,您应该能够在构建的输出中看到-v参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM