-1

In Jenkins, i need to limit running job execution for only one times per day It's possible ?

My build it's just one batch command

I have one cron for execute my job with fix times and i can use URL for run my job manually too. If the job has already been executed, it must be blocked for the day

Thx for answers guys

Antho03
  • 49
  • 1
  • 7
  • As this might not have a straight answer to do what you want , you can have a workaround using Restriction job plugin. You can prohibit manaul jobs and restrict jobs to be accepted by certain user, this way you can let the job trigger only if you accept it. https://wiki.jenkins.io/display/JENKINS/Job+Restrictions+Plugin – mbn217 Feb 04 '19 at 15:29
  • Thx for answer but i cant use this solution .. manual execution should works but only one times per day .. whatever the user – Antho03 Feb 04 '19 at 15:36
  • how about you add a command to disable your job and then waits until midnight to activate it again ? The Best way is to create a job that disable the finished job and then wait until midnight , then enable the job again . you can use this script to accomlish this import jenkins.* import jenkins.model.* try { Jenkins.instance.getItem("jobname").disable() } catch (Exception ex) { printf("Error disabling jobname. " + ex.getMessage()) } – mbn217 Feb 04 '19 at 15:49
  • Ye it's good idea but problem is that the job runs periodically in the night but I have to be able to run it via the URL once during the day – Antho03 Feb 04 '19 at 15:58
  • you said that the job should run only 1 time during a 24h period. So that solution should work for you. Because the job will be activated again after midnight and if you run it manually in the morning or its triggered by scedule , it should do the trick . Try it out first – mbn217 Feb 04 '19 at 16:01
  • OK but can u give me some details for do that ? I need to put this script in postbuild of my job so ? – Antho03 Feb 04 '19 at 16:08

1 Answers1

1

So let assume that your job name called TestJob , Create another job called DisableEnable_TestJob. In the DisableEnable_TestJob configure it to be triggered using Build trigger Build Trigger Then you can use Job DSL plugin to disactivate a specific TestJob and then activate after the system time is midnight. Refer to this answer to see how to use it: Activate and disactivate a job using DSL plugin . You have to search only for how to wait until midnight time but that should not be an issue. Once the time is at 12:00 then you can activate the job again.

Let me now if you need any more help

mbn217
  • 884
  • 7
  • 14