Mridang Agarwalla
Mridang Agarwalla

Reputation: 44958

How do I checkout a repository inside a Docker container when using a Jenkinsfile?

I've currently managed to set up a Jenkins file to run my PHP analysis inside a container. Here's the gist of it:

node {
    stage "Prepare environment"
        checkout scm
        def environment  = docker.build 'platforms-base'

        environment.inside {
            stage "Update Dependencies"
                sh "composer install || true"
        }
}

When this runs, it seems that the repo is checked out onto the host machine and that directory is mounted into the docker container in the /app directory. (I haven't found any configuration for this so I'm not sure where this is defined.)

In the same container, I have Magento2 installed in the /var/magento2 directory. I need to run some tests inside the scope of the Magento2 codebase. This means that I need to checkout the current branch into a particular directory in the container at /var/magento2/vendor/myorg/mypackage/ but the checked out repo seems to be at /app.

How do I checkout a repo in a certain place inside the container?

Upvotes: 1

Views: 4445

Answers (1)

Reinout van Rees
Reinout van Rees

Reputation: 13624

/app will be mounted inside your container because you (or the Dockerfile you're using) mounts the current directory as /app.

Now, your code is already checked out just fine by Jenkins, so I wouldn't do a separate extra checkout from inside the docker container. Jenkins just checked out the correct branch/master/tag for you with the proper credentials, so no need to do it yourself.

You've got three basic choices:

  • Mount the current directory not as /app, but as /var/magento2/vendor/myorg/mypackage/

  • Mount the current directory as both /app and /var/magento2/vendor/myorg/mypackage/. You could perhaps even do this with an extra command line option instead of modifying the Dockerfile. (This very much depends on your development setup).

  • Make /var/magento2/vendor/myorg/mypackage/ a symlink to /app, that will probably work, too.

Upvotes: 1

Related Questions