Jenkins' JobDSL Queue with Parameters

匆匆过客 提交于 2020-01-15 10:25:13

问题


Does anyone know if you can run a Jenkins' job from JobDSL that has parameters?

I have used queue https://jenkinsci.github.io/job-dsl-plugin/#path/queue

But according to the docs, it only accepts a string or Job object. Maybe there is a way to do it with Job object, but its not clear. From JobDSL docs:

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

queue(example1)

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

queue('example-2')

回答1:


Have same problem and couldn't find an answer in docs so I'm now looking at using system groovy script as per this example.

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.")
}

I'm using Jenkins 2.116 and Groovy plugin 2.0



来源:https://stackoverflow.com/questions/49659175/jenkins-jobdsl-queue-with-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!