I am creating a Jenkins pipeline. This pipeline creates three jobs (JobOne, JobTwo, JobThree). I can complete the task with the following code.
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'
}
Now I want to add some condition to it. For example, when JobOne fails, the job must be restarted again. When JobTwo passes, you want to run the job again. And JobThree should work 10 minutes after the completion of JobTwo. I am not sure how to make a pipeline with this condition. I am new to Jenkins project.
I checked several Jenkins WiKi pages, but could not find the right way to implement it if the condition is with the above conditions. I tried under the code to just check how the if condition could be met. But he fails.
node {
stage 'Stage 1'
echo 'Hello World 1'
build 'Pipeline-Test/JobOne'
post {
always{
build 'Pipeline-Test/JobOne'
}
}
Error:
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)
-, , ?
!