Last active
June 26, 2017 14:48
-
-
Save ndmanvar/d9f901acef8a036d83998e11b11279c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jenkins | |
import re | |
server = jenkins.Jenkins('http://ci.saucelabs-sales.net/', username='YOUR_JENKINS_USERNAME', password='YOUR_JENKINS_PASSWORD') | |
user = server.get_whoami() | |
version = server.get_version() | |
jobs = server.get_jobs() | |
for job in jobs: | |
name = job['fullname'] | |
try: | |
config = server.get_job_config(name) | |
if not 'Pipeline' in name: | |
update = True | |
if '<properties/>' in config: | |
new_config = config.replace('<properties/>', '<properties>\n <jenkins.model.BuildDiscarderProperty>\n <strategy class="hudson.tasks.LogRotator">\n <daysToKeep>30</daysToKeep>\n <numToKeep>30</numToKeep>\n <artifactDaysToKeep>-1</artifactDaysToKeep>\n <artifactNumToKeep>-1</artifactNumToKeep>\n </strategy>\n </jenkins.model.BuildDiscarderProperty>\n </properties>') | |
elif 'numToKeep' in config and 'daysToKeep' in config: | |
new_config = re.sub("<numToKeep>.*</numToKeep>", '<numToKeep>30</numToKeep>', config) | |
new_config = re.sub("<daysToKeep>.*</daysToKeep>", '<daysToKeep>30</daysToKeep>', new_config) | |
else: | |
update = False | |
print "Not found in " + name | |
if update: | |
server.reconfig_job(name, new_config) | |
except: | |
print "Error reconfiguring: " + name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment