Good day,
I need to run job in Jenkins monthly, two days before the end of the month.
The question is similar to question: run cron job on end of every month , but accepted response is not acceptable in my case. (Because modifying production code is out of scope and people would still like to execute it outside set hours.)
I found similar issues and potential solution in generic crontab environment:
0 23 27-30 * * [ $(date +\%d -d "2 days") == 01 ]
But Jenkins does not support this sort of syntax, giving me error message:
Invalid input: "0 23 27-30 * * [ $(date +\%d -d "2 days") == 01 ]": line 1:15: expecting EOF, found ' '
Any Jenkins gurus to give pointers?
Edit: With help of answer below, I came up with following solution:
- Add string parameter Autorun
- Set Crontab to
H 4 26-30 * *
- Modfied Execute script:
_
if (($Autorun == 0)) || (( [ $(date +\%d -d "2 days") == 01 ] && $Autorun == 1 )); then
My_execute stuff
else
echo "Dummy run, autorun only 2 days before end of month."
exit 1
fi