VSh
VSh

Reputation: 478

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.

Upvotes: 0

Views: 342

Answers (1)

StephenKing
StephenKing

Reputation: 37650

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.

Upvotes: 2

Related Questions