is there a way to get all the enabled jobs on a jenkins CI System

1,737 views
Skip to first unread message

Raj

unread,
Mar 21, 2017, 3:39:41 PM3/21/17
to Jenkins Users
I would like to know if there is a way to use jenkins cli jar file and find out if a given job is enabled or currently disabled. 
i have about 700 jobs on the server and would like to know the list of enabled and disabled jobs

Thank you very much for your time.
regards,
Raj

Baptiste Mathus

unread,
Mar 28, 2017, 4:42:11 PM3/28/17
to jenkins...@googlegroups.com
You should google for "Jenkins groovy script console".

That should be something like (untested) "Jenkins.instance.getItem('yourjob').isEnabled()"

And doing this for all of them would be along 

Jenkins.instance.getItems(Job.class).each { job ->
  println job.name + " => " + job.enabled 
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1f3e4cf9-64ab-48cb-8c36-7039b0ae99b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ramanathan Muthaiah

unread,
Mar 31, 2017, 9:42:14 AM3/31/17
to Jenkins Users
Raj,


I would like to know if there is a way to use jenkins cli jar file and find out if a given job is enabled or currently disabled. 
i have about 700 jobs on the server and would like to know the list of enabled and disabled jobs

Another way to get this done (if you have done prior Python programming) is to use REST APIs available in Jenkins.

It's quite fun to deep dive and learn.

/Ram

Prakash T

unread,
Oct 15, 2022, 3:47:50 AM10/15/22
to Jenkins Users
Hi , did you find the solution , even i m looking for the same.

Peter Kunst

unread,
Oct 15, 2022, 4:39:04 AM10/15/22
to jenkins...@googlegroups.com
A little off topic, because it doesn't use jenkins-cli.jar (-:
When your jenkins ssh port is accessible, you could use something like this:

#!/bin/sh
# check which jenkins jobs are enabled/disabled, using ssh
JENKINS_CONTROLLER=jenkins.my.org
JENKINS_SSH_PORT=2222
JENKINS_USER=jenkins
JOBS=$(ssh -l $JENKINS_USER -p $JENKINS_SSH_PORT $JENKINS_CONTROLLER list-jobs)
for J in $JOBS; do
STATUS=$(ssh -l $JENKINS_USER -p $JENKINS_SSH_PORT
$JENKINS_CONTROLLER get-job $J|grep disabled)
if [[ $STATUS = *false* ]]; then
echo "$J is enabled"
else
echo "$J is disabled"
fi
done

Cheers, Peter
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/05d52545-aa84-415f-a121-f1dbd87c7854n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages