我需要使用 DSL 将 Jenkins 管道向后移植到旧的 Jenkins 作业格式。我被困在代理部分:
agent {
dockerfile {
label 'buildDockerNode'
dir 'devops/k8s/build'
}
}
如何在旧 Jenkins 上使用此方法?在旧的 Jenkins 作业 DSL 中,我只看到相应管道语法的label
配置。 任何想法都是值得赞赏的。
通过使用 pipelineJob 属性,代理将由 pipelineDSL 配置。无需在作业DSL https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob 中再次定义它
为了简化向jobDSL的转换,我建议使用jenkins-pipelayer库,它为您抽象了jobDSL,您可以使用属性文件来配置管道。 文档在这里: https://github.com/SAP/jenkins-pipelayer/blob/master/USAGE.md#template-engine
我找到了buildInDocker
包装器的解决方案:
https://jenkinsci.github.io/job-dsl-plugin/#path/job-wrappers-buildInDocker
job('example-2') {
wrappers {
buildInDocker {
dockerfile()
volume('/dev/urandom', '/dev/random')
verbose()
}
}
}