HJ_VORTEX
HJ_VORTEX

Reputation: 31

Schedule same Jenkins job multiple times each time with different parameters

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

Upvotes: 2

Views: 10785

Answers (2)

Anne van Leyden
Anne van Leyden

Reputation: 138

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

Upvotes: 4

prudviraj
prudviraj

Reputation: 3744

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

Upvotes: 0

Related Questions