Giter Site home page Giter Site logo

jenkinsci / working-hours-plugin Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 14.0 1.37 MB

Jenkins plugin to prevent a build step from running outside working hours

Home Page: https://plugins.jenkins.io/working-hours/

License: MIT License

Java 99.89% HTML 0.11%

working-hours-plugin's Introduction

Working Hours Jenkins Plugin

Join the chat at https://gitter.im/jenkinsci/working-hours-plugin

The working hours plugin allows you to set up a schedule of allowable build times; projects can opt in to use the schedule to prevent them from running outside of configured allowable build times. If a build is scheduled during non-working hours then it is kept in the build queue until the next allowable time.

Jobs opt in via the enforceBuildSchedule job parameter, which is provided by this plugin. It can optionally take in a branches parameter to limit it's usage to only those branches. This only works in MultiBranchPipelines.

Usage

Sample job (scripted pipeline):

node {
  properties([enforceBuildSchedule()])
  stage('Do some stuff') {
    echo 'this can wait til morning'
  }
}

Sample job (declarative pipeline):

pipeline {
  agent any
  options {
    enforceBuildSchedule()
  }

  stages {
    stage('Do some stuff') {
      steps {
        echo 'this can wait til morning'
      }
    }
  }
}

Sample job with branches parameter (works in both declarative and scripted):

node {
  properties([enforceBuildSchedule(branches: ['dev', 'qa', 'prod')])
  stage('Do some stuff') {
    echo 'this can wait til morning'
  }
}

When the job runs outside of configured hours, you'll be able to see a tooltip from the job in the queue:

Queued job

You can also see why the job is blocked in the build log:

Blocked job

Releasing a blocked job

If you want a job to run anyway, you can use the Release job action which is available from various places, such as the build action dropdown:

Release job action

and the build page:

Release job action

Configuration

In order to use the working hours plugin, you must set up a schedule in your Jenkins system configuration page. You can configure both daily working hours and specific dates (such as holidays). The following configuration will cause jobs with enforceBuildSchedule to queue if ran outside of Monday - Friday 8:00 AM to 6:00 PM.

Note: all times are local to your Jenkins controller.

Configuration options

Allowable build times

This section contains the times when guarded steps are allowed for each day. Times can be entered in one of the following formats:

  • 24 hour eg 09:00, 18:00
  • Abbreviated 24 hour eg 0900, 1800
  • 12 hour eg 9:00 AM, 6:00 PM

Note All times are local to your Jenkins controller.

If the enforceBuildStep runs at a time that is not between a configured time range for the day it's running, the job will be aborted. Please note that if no allowable time ranges are configured for a day, enforceBuildStep will abort the job.

Excluded dates

This section contains explicit days (such as holidays) to abort the enforceBuildStep. This takes precedence over aAllowable build times, so jobs will always be queued on an excluded date. Here's an example of some holidays configured in the Working Days calendar:

Excluded days

working-hours-plugin's People

Contributors

based2 avatar dan-heath avatar ericbartusch avatar haxzie avatar jeffpearce avatar jxpearce-godaddy avatar oleg-nenashev avatar shenjack avatar zachary2940 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

working-hours-plugin's Issues

Working Hours Jenkins Plugin schedule didn't get triggered

We want to use the Working Hours Jenkins Plugin in our project to stop the Jenkins execution for the fixed time frame. When I configured the same under the system configuration, it didn't work the way expected. We are using Jenkins GUI to schedule the jobs. Please find the attached screenshot of my Working Hours Jenkins Plugin schedule. Am I missing something here? Would you please help me to go through this? I appreciate any help you can provide. (edited)

image

Allow custom text when jobs are held

When a job is held, the build log will contain the text "Outside working hours - job will run during next available time.".

It would be nice to have the ability to specify a different string in the UI as an option, and use that if provided.

Repeatable holiday

When entering holidays, it would be nice to have a way to indicate that date is a holiday every year (right now it only applies to the specific year). The easiest thing to do is probably to just add a checkbox to the UI.

More than one schedule

I would like to be able to define more than one schedule. My use cases:

  • I have some build jobs that I only want to run during office hours
  • I have some maintenance jobs that I only want to run outside office hours
  • I work in an international team, spread over several geographic locations and time zones. Office hours in Asia, Europe and Americas hardly overlap.

Option to cancel job and not queue it

I have a use case where I do not want jobs to run out side of office hours, however instead of queuing the job to run in office hours I'd like to just cancel/not run the job at all.

Any running jobs fail to resume after Jenkins restart with WorkingHours plugin installed

When the WorkingHours plugin is installed, any jobs that have it enabled via the enforceBuildSchedule() option that were running at the time of a restart, will fail to resume after Jenkins restarts, showing the following error repeatedly in their log:

Waiting to resume part of <job> » <job>:<run>: Exception evaluating if the queue can run the task

The Jenkins log shows this stacktrace:

Exception evaluating if the queue can run the task 'part of <job>'
java.lang.NullPointerException
	at org.jenkinsci.plugins.workinghours.WorkingHoursQueueTaskDispatcher.canRunNow(WorkingHoursQueueTaskDispatcher.java:120)
	at org.jenkinsci.plugins.workinghours.WorkingHoursQueueTaskDispatcher.canRun(WorkingHoursQueueTaskDispatcher.java:82)
	at hudson.model.Queue.getCauseOfBlockageForItem(Queue.java:1209)
	at hudson.model.Queue.maintain(Queue.java:1539)
	at hudson.model.Queue$MaintainTask.doRun(Queue.java:2904)
	at hudson.triggers.SafeTimerTask.run(SafeTimerTask.java:91)
	at jenkins.security.ImpersonatingScheduledExecutorService$1.run(ImpersonatingScheduledExecutorService.java:58)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

The only resolution is aborting and restarting the jobs.

System info:

Jenkins version: 2.249.1 (seen for several of the past LTS versions)
WorkingHours Plugin version: 1.0

Persistent "Could not parse into format" error

I have the working hours plugin installed on my Jenkins master, and whenever the local time is outside of the configured working hours, the log gets filled with hundreds of these error messages:

Could not parse into format HHmm
Could not parse into format HHmm
Could not parse into format HHmm
Could not parse into format HHmm
Could not parse into format HHmm
Could not parse into format HHmm
Could not parse into format HHmm
Could not parse into format HHmm
Could not parse into format HHmm
2021-02-25 23:33:48.642+0000 [id=133]    INFO    o.j.p.w.WorkingHoursQueueTaskDispatcher#log: Blocking item 345921
021-02-25 23:33:48.643+0000 [id=133]    INFO    o.j.p.w.WorkingHoursQueueTaskDispatcher#log: Blocking item 345922

I'm running the latest available version of the working hours plugin (1.1) with Jenkins 2.263.3, but this has been an issue for months now.

My configuration for the working hours plugin looks like so:
Screen Shot 2021-02-25 at 5 32 56 PM

I've tried changing 00:00 to 0:00, no change in the logging. The working hours plugin is working as expected - it's blocking jobs outside the configured working hours - yet it's still spamming the system log with these parse errors.

Limit holding jobs to certain branchs

It would be nice to be able to limit holding jobs to certain branches. One use case for this plugin is to prevent deployments, but those typically are scoped to certain branches. It would be nice to allow branches that don't deploy (such as PRs) to proceed.

One idea would be to add some properties, e.g.

enforceBuildSchedule(branches: ['master', 'prod', 'test'])

But other solutions are welcome

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.