How to update job config files using the Python API?

Article ID:218353568
1 minute readKnowledge base


I would like to be able to update job config files remotely using the Jenkins Python API.


  • CloudBees Jenkins Enterprise

  • Remote Access API

  • JenkinsAPI


Here is an example that replaces occurrences of oldvalue with newvalue in job test.


from jenkinsapi.jenkins import Jenkins

if __name__ == '__main__':
        jenkins = 'https://localhost:8080/'
        server = Jenkins(jenkins, username = 'admin', password = 'admin')
        job = server.get_job('test')
        new = config.replace('oldvalue', 'newvalue')

Obviously, replace:

  • username = 'admin', password = 'admin' with your username and password

  • https://localhost:8080/ with your Jenkins URL

  • test with your job name

See Remote Access API and JenkinsAPI for more.