作业DSL以创建“管道".打字工作 [英] Job DSL to create "Pipeline" type job

查看:113
本文介绍了作业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

推荐答案

您应使用您可以通过内联定义逻辑:

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以创建“管道".打字工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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