-
Notifications
You must be signed in to change notification settings - Fork 0
/
disable_jenkins_jobs.py
35 lines (26 loc) · 1.14 KB
/
disable_jenkins_jobs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'''
@author: sumit
This script will disable all Jenkins jobs present in the Jenkins home directory.
For this it become active we do need to reload all configuration from disk once the script has run.
To reload configuration go to Jenkins -> Manage Jenkins -> Reload Configuration from Disk
OR
Restart Jenkins
'''
import os
from subprocess import *
import xml.etree.ElementTree as ET
class DisableJenkinsJobs():
def disableAllJenkinsJobs(self):
jenkinsJobDirectory = "/usr/lib/jenkins/jobs/" #This is the home directory of Jenkins
for root, dirs, files in os.walk(jenkinsJobDirectory):
for file in files:
if file.endswith('config.xml'):
full_path_file = (os.path.join(root, file))
tree = ET.parse(full_path_file)
root = tree.getroot()
for disabled in root.findall('disabled'):
disabled.text = "true"
# this needs SUDO access so run the script with sudo permission
tree.write(full_path_file)
JenkinsObject = DisableJenkinsJobs()
JenkinsObject.disableAllJenkinsJobs()