job-dsl

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
    ])

Last updated