Temporarily stop all scheduled jobs in Jenkins from running
Asked Answered
S

6

6

I'm in the process of migrating Jenkins from one server to another. I've no issues with the migration process.

But sooner I start my new server the scheduled jobs start executing, which is proving to be dangerous. I need to make sure that everything is in place before activating the new server.

Is there any way to deter any of the jobs from executing while the new server is active?

Salop answered 13/10, 2017 at 9:52 Comment(1)
How did you solve this?Goldfinch
G
1

Setup a post-initialization script that puts Jenkins into quiet mode right after startup.

https://wiki.jenkins.io/display/JENKINS/Post-initialization+script

Goldfinch answered 13/10, 2017 at 14:35 Comment(0)
R
3

execute an '/script':

Jenkins.instance.getAllItems(org.jenkinsci.plugins.workflow.job.WorkflowJob.class).each {i -> i.setDisabled(true); i.save() }
Jenkins.instance.getAllItems(hudson.model.AbstractProject.class).each {i -> i.setDisabled(true); i.save() }

Not my idea, from jenkins wiki

Raised answered 20/8, 2018 at 9:2 Comment(0)
B
1

Try using https://wiki.jenkins.io/display/JENKINS/Exclusive+Execution+Plugin. You can keep jenkins in shutdown or Quiet mode for some time till your new instance is ready to function.

Bernardinabernardine answered 13/10, 2017 at 13:48 Comment(0)
G
1

Setup a post-initialization script that puts Jenkins into quiet mode right after startup.

https://wiki.jenkins.io/display/JENKINS/Post-initialization+script

Goldfinch answered 13/10, 2017 at 14:35 Comment(0)
R
0

Use the Jenkins CLI

To prevent any jobs from being run, use quiet-down:

java -jar jenkins-cli.jar -s http://localhost:9090 -auth user:token quiet-down

To re-enable job scheduling:

java -jar jenkins-cli.jar -s http://localhost:9090 -auth user:token cancel-quiet-down

Scheduled jobs will be added to the queue during the quiet-down time, and will be run after canceling the quiet-down. If that's not what you want, you may use clear-queue before canceling the quiet-down.

There is a little downside: in the GUI, Jenkins will announce that it is preparing for shutdown, which wouldn't be true in this case. I find that acceptable, because we use it during backup at night when no one will read the announcement anyway. However, another option would be to take nodes offline, then online again using offline-node and online-node.


Quick Setup

Only if you haven't set up Jenkins CLI already:

  • You can obtain the Jenkins CLI from your Jenkins server by downloading it from <your_jenkins_url>/jnlpJars/jenkins-cli.jar
  • Instead of using your actual password to authenticate, obtain a token from <your_jenkins_url>/me/configure
  • For more details, refer to the Jenkins Handbook: Jenkins CLI
Rackety answered 9/9, 2022 at 10:20 Comment(0)
M
0

Referencie: https://xanderx.com/post/cancel-all-queued-jenkins-jobs/

Run this in Manage Jenkins > Script Console:

Jenkins.instance.queue.clear()

Mccarley answered 17/11, 2022 at 8:46 Comment(0)
F
0

From the Jenkins console, click "Manage Jenkins" then "Prepare for Shutdown" (probably at the very bottom of the page). This will stop running new jobs, so the list of scheduled jobs will become very long but they will not execute until after a reboot.

Fervid answered 26/8 at 7:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.