0

I want my pipeline created using Blue Ocean (Jenkins) to build with a dockerfile that is not in the root of the git repo. How do I achieve this?

Our git repo is a collection of sub-projects with each containing it's own dockerfile. So we cannot place them in the root directory.

1

From the official instructions on building Docker images with Jenkins Pipeline:

The build() method builds the Dockerfile in the current directory by default. This can be overridden by providing a directory path containing a Dockerfile as the second argument of the build() method, for example:

node {
    checkout scm
    def testImage = docker.build("test-image", "./dockerfiles/test") 

    testImage.inside {
        sh 'make test'
    }
}

I'm not sure if you can create a Pipeline (i.e. Jenkinsfile) with this exact configuration through the Blue Ocean UI, but I would imagine you can. However, I personally have found using Blue Ocean to create pipelines to be finicky at best, so I would recommend going over a Jenkinsfile created by Blue Ocean and making tweaks and adjustments by hand anyway. This would give you the opportunity to adjust the Dockerfile location even if you aren't able to do it via Blue Ocean.

1
node {
checkout scm 
app = docker.build("test-image","-f path/to/dockerfile .")
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.