用于创建“管道"的作业 DSL类型工作 [英] Job DSL to create "Pipeline" type job

查看:25
本文介绍了用于创建“管道"的作业 DSL类型工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了Pipeline Plugin,它以前被称为Workflow Plugin.

解决方案

你应该使用 pipelineJob:

pipelineJob('job-name') {定义 {cps {脚本('逻辑在这里')沙箱()}}}

您可以通过内联来定义逻辑:

pipelineJob('job-name') {定义 {cps {脚本('''管道{代理任何阶段{阶段('阶段 1'){脚步 {回声逻辑"}}阶段('阶段 2'){脚步 {回声逻辑"}}}}}'''.stripIndent())沙箱()}}}

或从位于工作区中的文件加载它:

pipelineJob('job-name') {定义 {cps {脚本(readFileFromWorkspace('file-seedjob-in-workspace.jenkinsfile'))沙箱()}}}

示例:

种子作业文件结构:

工作- productJob.groovy逻辑- productPipeline.jenkinsfile

然后 productJob.groovy 内容:

pipelineJob('product-job') {定义 {cps {脚本(readFileFromWorkspace('logic/productPipeline.jenkinsfile'))沙箱()}}}

I have installed Pipeline Plugin which used to be called as Workflow Plugin earlier.
https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin

I want to know how can i use Job Dsl to create and configure a job which is of type Pipeline

解决方案

You should use 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()     
    }
  }
}

Example:

Seed-job file structure:

jobs
   - productJob.groovy
logic
   - productPipeline.jenkinsfile

then productJob.groovy content:

pipelineJob('product-job') {
  definition {
    cps {
      script(readFileFromWorkspace('logic/productPipeline.jenkinsfile'))
      sandbox()     
    }
  }
}

这篇关于用于创建“管道"的作业 DSL类型工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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