作业DSL创建"管道"类型的作业

mea*_*our 24 jenkins jenkins-plugins jenkins-job-dsl jenkins-workflow jenkins-pipeline

我安装Pipeline Plugin了以前调用Workflow Plugin过的.
https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin

我想知道如何使用Job Dsl创建和配置类型的作业 Pipeline

在此输入图像描述

aga*_*rys 25

你应该用pipelineJob.

例:

pipelineJob('job-name') {
  definition {
    cps {
      script('logic-here')
      sandbox()
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

  • -1 不要只在 `node` 声明中运行 `build` 阶段。这将为管道分配一个完整的执行程序,该执行程序将等待触发的构建完成。最好的情况是浪费,最坏的情况是会导致死锁。你可以跳过节点块,一个享元执行器将被动态分配,而不会消耗一个完整的执行器。 (3认同)

J.Z*_*.Z. 23

我相信这个问题是询问如何使用Job DSL创建一个管道作业,该作业引用项目的Jenkins文件,并且不会将作业创建与详细的步骤定义结合起来,如日期答案中给出的那样.这是有道理的:Jenkins作业创建和元数据配置(描述,触发器等)可能属于Jenkins管理员,但开发团队应该控制作业实际执行的操作.

@meallhour,以下是你的追求?(在Job 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' << '' } )
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

参考Job DSL管道工作: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 = 'git@git.company.com: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 
        } 
      } 
    } 
  }
Run Code Online (Sandbox Code Playgroud)

如果首先通过UI构建管道,则可以使用config.xml文件和Jenkins文档https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob来创建管道作业.


das*_*ker 6

在Job DSL中,管道仍称为工作流,请参阅workflowJob.

下一个Job DSL版本将包含一些管道增强功能,例如JENKINS-32678.