Reputation: 308
I have a couple of jobs both would trigger on Monday but 1 st project on 1st Monday and 2nd project on 2nd Monday. I couldn't use the Jenkins cron to trigger the project based on condition because cron can be used to trigger a project on a specific time of the day or week of the day alone (eg 0 6 ** 1 to trigger project on Monday morning 6 AM) and not based on condition.
I am looking for a solution where I could use the cron to trigger the project but it would have some condition only if it passes the project would be triggered.
Upvotes: 0
Views: 4497
Reputation: 26
Currently jenkins cron doesn't support triggering project based on condition. You can do this in two ways
ii)Once the project is triggered you write a condition either using windows batch command or shell script to check if the current week is as expected (Odd/Even) if it meet the condition you proceed the next step or fail it.
But the issue with this solution is you will have a unnecessary project.
ii)In the parent project execute a shell/windows batch command to check if the current week is odd or even refer - Date convert to week number based on it you create a variable and set value as true or false and then write the values into a property file
iii)Then convert the value as a environment variable using Jenkins Environment Injector Plugin (url - https://plugins.jenkins.io/envinject/) for details on how to convert refer - How to set environment variables in Jenkins?, Now you can access the value across the project
iv)Create a new conditional build step (Plugin url - https://plugins.jenkins.io/conditional-buildstep/ ) In that trigger your child project based on comparison of environment variable with a expected condition (i.e if "TRUE" then trigger Odd week project)
Upvotes: 1
Reputation: 6859
You can trigger the build, check the condition, and bail out of the build if the condition does not hold. You can optionally fail the build in this case.
Upvotes: 1