references:
- * jenkinsci/job-dsl-plugin
- * jenkins-pipeline-library/jobs/devops/seed.groovy
- * Jenkins DSL seed job
- Jenkins Tutorial
- * User Power Moves
- * Getting Started With Jenkins Job DSL Plugin for Standardising Your Pipelines
- * Jenkins DSL seed job
- Jenkins: 使用groovy + job-dsl 创建并触发job
- Jenkins Job DSL API
- Groovy DSL is not working
- job-dsl-plugin/src/test/groovy/javaposse/jobdsl/plugin/ExecuteDslScriptsSpec.groovy
- Using Jenkins Job DSL plugin to automatically create and configure projects with Perforce
- Jenkins-as-code
- How To Automate Jenkins Setup with Docker and Jenkins Configuration as Code
dsl in jenkinsfile
timestamps { ansiColor('xterm') {
node('built-in') {
jobDsl (
sandbox: true,
scriptText: '''
pipelineJob(\'github-demo\') {
definition {
cpsScm {
scm {
git {
remote { github(\'jenkinsci/pipeline-examples\') }
}
}
scriptPath(\'declarative-examples/simple-examples/environmentInStage.groovy\')
}
}
}
'''
) // jobDsl
} // node
}} // ansiColor | timestamps
- or via
ExecuteDslScripts
step ([ $class: 'ExecuteDslScripts' , scriptText: """ pipelineJob('dsl/guardian/demo') { definition { cpsScm { scm { git { remote { github('jenkinsci/pipeline-examples') } } } scriptPath( 'declarative-examples/simple-examples/environmentInStage.groovy' ) } } } """.stripIndent() , sandbox: true ]) // steps
create folder
timestamps { ansiColor('xterm') {
node('built-in') {
jobDsl (
ignoreExisting: true,
sandbox: true,
scriptText: '''folder(\'dsl\') {
displayName(\'dsl\')
description(\'for dsl demo\')
}'''
)
} // node
}} // ansiColor | timestamps
- or via
ExecuteDslScripts
step([ $class: 'ExecuteDslScripts', scriptText: """ folder('dsl/guardian') { displayName('guardian') description('for dsl guardian demo') } """ , lookupStrategy: 'JENKINS_ROOT', removedJobAction: 'DELETE', removedViewAction: 'DELETE', sandbox: true ])