本文介绍了作业DSL以创建“管道".打字工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经安装了Pipeline Plugin
,它以前曾被称为Workflow Plugin
.
https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin
I have installed Pipeline Plugin
which used to be called as Workflow Plugin
earlier.
https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin
我想知道如何使用Job Dsl创建和配置Pipeline
I want to know how can i use Job Dsl to create and configure a job which is of type Pipeline
推荐答案
您应使用 pipelineJob
:
pipelineJob('job-name') {
definition {
cps {
script('logic-here')
sandbox()
}
}
}
您可以通过内联定义逻辑:
You can define the logic by inlining it:
pipelineJob('job-name') {
definition {
cps {
script('''
pipeline {
agent any
stages {
stage('Stage 1') {
steps {
echo 'logic'
}
}
stage('Stage 2') {
steps {
echo 'logic'
}
}
}
}
}
'''.stripIndent())
sandbox()
}
}
}
或从工作区中的文件加载它:
or load it from a file located in workspace:
pipelineJob('job-name') {
definition {
cps {
script(readFileFromWorkspace('file-seedjob-in-workspace.jenkinsfile'))
sandbox()
}
}
}
示例:
种子文件结构:
jobs
\- productJob.groovy
logic
\- productPipeline.jenkinsfile
然后productJob.groovy
内容:
pipelineJob('product-job') {
definition {
cps {
script(readFileFromWorkspace('logic/productPipeline.jenkinsfile'))
sandbox()
}
}
}
这篇关于作业DSL以创建“管道".打字工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!