简体   繁体   中英

Jenkins build agent docker specify docker file name

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM