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

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

问题描述

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

解决方案

你应该使用 pipelineJob:

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

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

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

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

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

例子:

种子作业文件结构:

职位- productJob.groovy逻辑- productPipeline.jenkins 文件

然后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()     
    }
  }
}

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

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