2
votes

I have a Jenkins parametrised job which I want to schedule nightly, morning and weekly. Its basically a startup/shutdown environment job which shutsdown the environment during night and start it up early in the morning and weekends are different schedule. so how can I do this without creating three separate jobs ?

I need to build this job on different times 1) every (MON-FRI) weekday morning 7 am START environment 2) every (MON-FRI) weekday evening 8 pm STOP environment

2
So do you need 3 parameters ? Or do you want to build this job on 3 different times? For example H 9,17 * * * means it will build at 9 am and 5 pmAnuja Lamahewa
I need to build this job on different times 1) every (MON-FRI) weekday morning 7 am START environmet 2) every (MON-FRI) weekday evening 8 pm STOP environmentHJ_VORTEX
If you're trying to avoid duplicating the steps in the build, you could have 3 jobs set up to run at your different times, then have them all trigger the same job that starts/stops the environment. I don't think it's possible to do it all in one job.Brendan

2 Answers

4
votes

By default, Jenkins is not able to do what you want, but the Parameterized Scheduler plugin adds the functionality that you need. It allows you to specify multiple schedules with custom parameter values for each one, like this:

#lets run against the integration environment at 15 past the hour
15 * * * * % env=int
#run QA too
30 * * * % env=qa
0
votes

Can Give You a idea how to avoid creating multiple jobs for your requirement.

  1. First you need to trigger your job at 7 Am and 8 pm using build schedule

  2. Use Below script

Below script will check if you are running at morning or night , in weekdays or weekends and according to the timing it will either start/stop your environment

As said earlier this just an idea that will help you to approach , you need to tweak below code to meet your exact requirement

Note : Replace the echo section in start and stop part of goto with you code to start and stop environment

@echo off
echo Current Date and Time %date%-%time%

for /f %%a in ('date /t') do set "d=%%a"

set "t=%time:~0,2%"


if %t% GTR 12 goto Ni
if %t% LSS 12 goto Day

:Day

if %d% == Mon goto start
if %d% == Tue goto start
if %d% == Wed goto start
if %d% == Thu goto start
if %d% == Fri goto start
if %d% == Sat goto TBD
if %d% == Sun goto TBD


:Ni

if %d% == Mon goto stop
if %d% == Tue goto stop
if %d% == Wed goto stop
if %d% == Thu goto stop
if %d% == Fri goto stop
if %d% == Sat goto TBD
if %d% == Sun goto TBD


:start

echo start an application

goto last

:stop

echo stop an application


:last

echo last line