Jenkins 的带参数的 JobDSL 队列

Jenkins' JobDSL Queue with Parameters

有谁知道你是否可以 运行 Jenkins 的 JobDSL 作业,它有参数?

我用过队列https://jenkinsci.github.io/job-dsl-plugin/#path/queue

但根据文档,它只接受字符串或作业对象。也许有一种方法可以用 Job 对象来做,但还不清楚。来自 JobDSL 文档:

def example1 = job('example-1') {
   displayName('first example')
}

queue(example1)

job('example-2') {
    displayName('second example')
}

queue('example-2')

有同样的问题,但在文档中找不到答案,所以我现在正在考虑根据此 example.

使用系统 groovy 脚本
def job = Hudson.instance.getJob('MyJobName')
def anotherBuild
try {
    def params = [
      new StringParameterValue('FOO', foo)
    ]
    def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params))
    println "Waiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
    anotherBuild = future.get()
} catch (CancellationException x) {
    throw new AbortException("${job.fullDisplayName} aborted.")
}

我正在使用 Jenkins 2.116 和 Groovy 插件 2.0