作业DSL创建“管道”类型作业
问题描述:
我已经安装了Pipeline Plugin
,之前称其为Workflow Plugin
。
https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin作业DSL创建“管道”类型作业
我想知道我该如何使用工作的DSL创建和配置工作,这是类型Pipeline
答
如果您使用的是git repo,请在repo的根目录下添加一个名为Jenkinsfile的文件。这应该包含你的工作dsl。
答
您应该使用pipelineJob
。
例子:
pipelineJob('Pipeline') {
definition {
cps {
sandbox()
script("""
node {
stage('init') {
build 'Pipeline-init'
}
stage('build') {
build 'Pipeline-build'
}
}
""".stripIndent())
}
}
}
答
我相信这个问题是问一些如何使用工作DSL创建一个管道的工作它引用Jenkinsfile的项目,以及不与具体相结合的创造就业机会按照迄今为止的答案给出的步骤定义。这是有道理的:詹金斯的工作创建和元数据配置(描述,触发器等)可能属于詹金斯管理员,但开发团队应该能够控制工作的实际效果。
@meallhour,下面是你之后? (如工作在工作DSL 1.64)
pipelineJob('DSL_Pipeline') {
def repo = 'https://github.com/path/to/your/repo.git'
triggers {
scm('H/5 * * * *')
}
description("Pipeline for $repo")
definition {
cpsScm {
scm {
git {
remote { url(repo) }
branches('master', '**/feature*')
scriptPath('misc/Jenkinsfile.v2')
extensions { } // required as otherwise it may try to tag the repo, which you may not want
}
// the single line below also works, but it
// only covers the 'master' branch and may not give you
// enough control.
// git(repo, 'master', { node -> node/'extensions' << '' })
}
}
}
}
参考作业DSL pipelineJob:https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob,和谬以千里,在它http://job-dsl.herokuapp.com/查看生成的配置。
这个例子为我工作。下面是基于对我工作的另一个例子:
pipelineJob('Your App Pipeline') {
def repo = 'https://github.com/user/yourApp.git'
def sshRepo = '[email protected]:user/yourApp.git'
description("Your App Pipeline")
keepDependencies(false)
properties{
githubProjectUrl (repo)
rebuild {
autoRebuild(false)
}
}
definition {
cpsScm {
scm {
git {
remote { url(sshRepo) }
branches('master')
scriptPath('Jenkinsfile')
extensions { } // required as otherwise it may try to tag the repo, which you may not want
}
}
}
}
如果通过UI先建管道,您可以使用config.xml文件和文件詹金斯向https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob创建管道的工作。