【发布时间】:2017-12-08 10:54:59
【问题描述】:
我在声明式管道中有许多类似的配置,例如代理、工具、选项或帖子部分。是否有任何选项可以以某种方式定义这些选项,以便单个作业只需定义步骤(可能来自共享库)?
有一个description at "Defining a more stuctured DSL",其中有一些类似于我想要实现的东西,但这似乎适用于脚本化管道。
pipeline {
agent {
label 'somelabel'
}
tools {
jdk 'somejdk'
maven 'somemaven'
}
options {
timeout(time: 2, unit: 'HOURS')
}
stages {
stage('do something') {
steps {
doSomething()
}
}
}
post {
failure {
emailext body: '${DEFAULT_CONTENT}', subject: '${DEFAULT_SUBJECT}',
to: 'some@mail.com', recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider'], [$class: 'DevelopersRecipientProvider']]
}
}
}
实际上,我尝试了类似that 的方法,试图将闭包传递给管道,但这似乎不起作用。如果它有效,可能会有一些关于如何做到这一点的文档。
def call(stageClosure) {
pipeline {
agent {
label 'somelabel'
}
tools {
jdk 'somejdk'
maven 'somemaven'
}
options {
timeout(time: 2, unit: 'HOURS')
}
stages {
stageClosure()
}
post {
failure {
emailext body: '${DEFAULT_CONTENT}', subject: '${DEFAULT_SUBJECT}',
to: 'some@mail.com', recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider'], [$class: 'DevelopersRecipientProvider']]
}
}
}
}
并以某种方式这样称呼它:
library 'my-library@master'
callJob{
stage('do something') {
steps {
doSomething()
}
}
}
【问题讨论】:
-
我认为共享库现在不能很好地与声明性管道配合使用。共享库可以声明整个管道,也可以不声明。
-
使用声明性管道制作共享库有几个困难,因此我们必须等待社区提供一些解决方案
标签: jenkins groovy closures jenkins-pipeline jenkins-declarative-pipeline