简体   繁体   中英

How to hold the current Jenkins job execution until the dependency job completion in post build action

I have a scenario to trigger an another build in POST BUILD ACTION, and It will take 1m to complete and I just want to make the current build to wait until that dependency job complete (1m duration) and update the status (COMPLETED,FAILED,UNSTABLE).

It's like I have a job name called A and B. B is the dependency which needs to run in POST BUILD ACTION in JOB A. Once the JOB B completed the execution (1M duration) I want to publish the status of JOB A. JOB A needs to be hold until the JOB B execution complete in POST BUILD ACTION.

How can I achieve this? Any leads...

It's quite easy if you don't restricted to do it only in Post Build section (eg, when you need to trigger other build only if the main build is stable, but I think that with 1min job you just don't care about that).

You just need to install Parameterized Trigger plugin and it will allow you to add Trigger/call builds on other projects section in your Build section (not in Post Build ). And you need also to enable Block until the triggered projects finish their builds option to wait until your job B is finished and check the status of job B: 在此处输入图片说明

Sounds like a tricky problem to resolve as POST BUILD means that the job B will trigger AFTER job A is completed.

Something that you can try is to trigger the Job A and B in parallel and for the Job B you can add a build step to Execute shell with for example sleep 5m , so the Job B will sleep 5 minutes at the beginning and then it will run the actual job you want. In the Job A you can then have a shell script which will in loop read the console output of Job B and the loop will finish after the console of Job B will produce the output Finished: and then you can continue with the logic based on the job output.

For reading the console output, you can do something like this in a loop (and grep for the Finished: keyword):

curl -u ${USERNAME}:${TOKEN} {JENKINS_URL}/job/{JOB_NAME}/lastBuild/consoleText | grep {what you need}

You need to leverage the PostBuildScript plugin together with the Parameterized Trigger plugin. PostBuildScript will give you a post-build step called Execute scripts, which will enable you to add a Parameterized Trigger build step in the post-build stage. Thus, you can configure that to wait for the triggered job's completion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM