【发布时间】:2017-04-19 14:30:38
【问题描述】:
我正在创建一个 Jenkins 管道。该管道正在构建三个作业(JobOne、JobTwo、JobThree)。我可以使用以下代码运行该作业。
node {
stage 'Stage 1'
echo 'Hello World 1'
build 'Pipeline-Test/JobOne'
stage 'Stage 2'
echo 'Hello World 2'
build 'Pipeline-Test/JobTwo'
stage 'Stage 3'
echo 'Hello World 3'
build 'Pipeline-Test/JobThree'
}
现在我想在其中设置一些条件。例如,当 JobOne 失败时,作业必须再次重新启动。当 JobTwo 通过时,要再次运行作业。 JobThree 应该在 JobTwo 完成后 10 分钟后运行。我不确定如何在这种情况下制作管道。我是 Jenkins 管道的新手。
我检查了几个 Jenkins WiKi 页面,但找不到在上述条件下实现 if 条件的正确方法。我尝试了下面的代码只是为了检查如何实现“if”条件。但它失败了。
node {
stage 'Stage 1'
echo 'Hello World 1'
build 'Pipeline-Test/JobOne'
post {
always{
build 'Pipeline-Test/JobOne'
}
}
错误:
java.lang.NoSuchMethodError: No such DSL method 'post' found among [archive, bat, build, catchError, checkout, checkpoint, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, error, fileExists, git, input, isUnix, load, mail, node, parallel, properties, publishHTML, pwd, readFile, retry, sh, sleep, sshagent, stage, stash, step, teamconcert, timeout, tool, triggerRemoteJob, unarchive, unstash, waitUntil, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeFile, ws]
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:107)
有人可以指导我完成这个吗?
提前致谢!
【问题讨论】:
标签: if-statement jenkins groovy jenkins-pipeline