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

前端 未结 2 1933
我寻月下人不归
我寻月下人不归 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:42

    If you only need to create one simple pipeline job, you can use the Jenkins API. But that really only works well when creating one simple job, for a complex setup you need some abstraction like Job DSL.

    Start here: http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html#createProject(java.lang.Class,%20java.lang.String).

    Example:

    import jenkins.model.Jenkins
    import org.jenkinsci.plugins.workflow.job.WorkflowJob
    
    WorkflowJob job = Jenkins.instance.createProject(WorkflowJob, 'my-pipeline')
    

    Then you need to populate the job, e.g. setting a flow definition.

    Or you can wait for the System Config DSL Plugin to be ready. But it has not been released yet and I'm not sure if it can create jobs.

提交回复
热议问题