Jenkins build agent docker specify docker file name
Asked Answered
H

1

5

I was following this snippet to add to docker file for jenkins build agent (https://www.jenkins.io/doc/book/pipeline/docker/),

pipeline {
agent { dockerfile true }
stages {
    stage('Test') {
        steps {
            sh 'node --version'
            sh 'svn --version'
        }
    }
}
}

'dockerfile true' looks for the default Dockerfile. Is there a way to specify the docker file name as I don't want to use the default one because my settings would be different than the one already there?

Haulm answered 22/12, 2021 at 15:51 Comment(0)
B
6

Yes, you can absolutely specify the dockerfile file name in the agent directive. An example of this (with other arguments for the dockerfile parameter in agent) would be:

agent { // agent directive
  // Equivalent to "docker build -f Dockerfile.build --build-arg version=1.0.2 ./build/
  dockerfile { // dockerfile parameter
    filename             'Dockerfile.build' // filename argument and value
    dir                  'build'
    label                'my-defined-label'
    additionalBuildArgs  '--build-arg version=1.0.2'
    args                 '-v /tmp:/tmp'
  }
}

In the documentation for pipeline agent parameters, you can scroll down to the dockerfile parameter to view the arguments for the parameter and how they allow agent customization.

Burns answered 22/12, 2021 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.