简体   繁体   中英

How to use dockerfile agent in Jenkins DSL script

I need to back-port the Jenkins pipeline to old Jenkins job format with DSL. I'm stuck at the agent section:

agent {
    dockerfile {
        label 'buildDockerNode'
        dir 'devops/k8s/build'
    }
}

How can I use this method on old Jenkins? In old Jenkins job DSL I only see the label configuration for the corresponding Pipeline syntax. Any idea is appreciated.

By using the pipelineJob property, your agent will be configured by the pipelineDSL. No need to define it again in jobDSL https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob

To ease the transformation to jobDSL, I would recommend to use the jenkins-pipelayer library it abstracts jobDSL for you and you can use properties files to configure your pipeline. the docs is here: https://github.com/SAP/jenkins-pipelayer/blob/master/USAGE.md#template-engine

I found the solution with buildInDocker wrapper:

https://jenkinsci.github.io/job-dsl-plugin/#path/job-wrappers-buildInDocker

job('example-2') {
    wrappers {
        buildInDocker {
            dockerfile()
            volume('/dev/urandom', '/dev/random')
            verbose()
        }
    }
}

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