简体   繁体   中英

Understanding Jenkinsfile's steps for Docker agent

I have Jenkinsfile with the following steps:

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.

If that is true, then why the second step's sh command is executed successfully? How can it access the file on the Jenkins host?

To me, it looks like the commands are executed on the Jenkins host. Then why mvn clean install works fine? Jenkins host doesn't have Maven installed.

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. Otherwise, in probably 99% of all jobs, one would have to specify that the checked out repo should be mounted into the container.

You should be able to see the -v parameters in the output of the build when it issues the docker run command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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