在init.groovy.d脚本中使用管道初始化Jenkins 2.0 [英] Initializing Jenkins 2.0 with pipeline in init.groovy.d script

查看:422
本文介绍了在init.groovy.d脚本中使用管道初始化Jenkins 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于自动化,我想用管道工作初始化一个Jenkins 2.0实例。我想创建一个Groovy脚本,该脚本在启动时复制到 /usr/share/jenkins/ref/init.groovy.d / 文件夹中。该脚本应该创建一个Jenkins 2.0管道作业来处理来自SCM的Jenkinsfile。



我无法找到2.0管道类的相关Javadoc或如何执行此操作的示例。

以前,使用Job DSL创建管道,我使用Groovy脚本创建 FreeStyleProject ,并使用 ExecuteDslScripts 构建器。这项工作将是Job DSL的种子工作。



一种选择是使用init脚本创建Job DSL种子作业来创建Jenkins 2.0管道。这似乎不必要的复杂。



我正在试验这个回购: https://github.com/martinmosegaard/vigilant-sniffle

解决方案

如果您只需要创建一个简单的管道作业,您可以使用Jenkins API。但是,当创建一个简单的工作时,这真的只会工作得很好,对于一个复杂的设置,您需要像Job DSL这样的抽象。



从这里开始: http://javadoc.jenkins-ci.org /jenkins/model/Jenkins.html#createProject(java.lang.Class,%20java.lang.String)



示例:

  import jenkins.model.Jenkins 
import org.jenkinsci.plugins.workflow.job.WorkflowJob

WorkflowJob job = Jenkins.instance.createProject(WorkflowJob,'my-pipeline')

然后您需要填充工作,例如设置流程定义。



或者您可以等待系统配置DSL插件准备就绪。但它尚未发布,我不确定它是否能创造就业机会。


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.groovy.d/ folder on startup. The script should create a Jenkins 2.0 Pipeline job for processing a Jenkinsfile from SCM.

I cannot find the relevant Javadoc for the 2.0 pipeline classes or examples of how to do this.

Previously, using Job DSL to create a pipeline, I used a Groovy script to create a FreeStyleProject with an ExecuteDslScripts builder. That job would then be the Job DSL seed job.

One option is to use an init script to create a Job DSL seed job to create a Jenkins 2.0 pipeline. It just seems unnecessarily complex.

I am experimenting in this repo: https://github.com/martinmosegaard/vigilant-sniffle

解决方案

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.

这篇关于在init.groovy.d脚本中使用管道初始化Jenkins 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆