Initializing Jenkins 2.0 with pipeline in init.groovy.d script

前端 未结 2 1972
我寻月下人不归
我寻月下人不归 2021-02-06 11:13

For automation, I would like to initialize a Jenkins 2.0 instance with a pipeline job. I want to create a Groovy script that is copied to the /usr/share/jenkins/ref/init.g

2条回答
  •  我寻月下人不归
    2021-02-06 11:33

    With Job DSL 1.47 (to be released soon) you can use the Job DSL API directly from the init script without the need to create a seed job.

    import javaposse.jobdsl.dsl.DslScriptLoader
    import javaposse.jobdsl.plugin.JenkinsJobManagement
    
    def jobDslScript = new File('jobs.groovy')
    def workspace = new File('.')
    
    def jobManagement = new JenkinsJobManagement(System.out, [:], workspace)
    
    new DslScriptLoader(jobManagement).runScript(jobDslScript.text)
    

    See PR #837 for details.

提交回复
热议问题