Issue
I would like to be able to update job config files remotely using the Jenkins Python API.
Environment
- CloudBees Jenkins Enterprise
- Remote Access API
- JenkinsAPI
Resolution
Here is an example that replaces occurrences of oldvalue
with newvalue
in job test
.
#!/usr/bin/python
from jenkinsapi.jenkins import Jenkins
if __name__ == '__main__':
jenkins = 'http://localhost:8080/'
server = Jenkins(jenkins, username = 'admin', password = 'admin')
job = server.get_job('test')
config=job.get_config()
new = config.replace('oldvalue', 'newvalue')
job.update_config(new)
Obviously, replace:
username = 'admin', password = 'admin'
with your username and passwordhttp://localhost:8080/
with your Jenkins URLtest
with your job name
See Remote Access API and JenkinsAPI for more.
2 Comments