How to point on the concrete Dockerfile for the docker build command inside the jenkins pipeline?

Please let me know how to point on the concrete Dockerfile for the docker build command inside the jenkins pipeline?

I am trying to give a docker build from a Jenkins pipeline, I am using a common code to run this build and would want the pipeline to access a folder where the dockerfile is. How do I let the docker know how to find this dockerfile which is in a different folder location.

1 answer

  • answered 2020-06-02 11:37 crash

    With sh in a declarative pipeline:

    sh '''
        docker build -t '<myimagename>' \
            --file <somewhereelse>/Dockerfile .
    '''
    

    Within a scripted pipeline:

    docker.build("my-image:${env.BUILD_ID}", "-f ${dockerfile} ./dockerfiles")