Python jenkinsapi - disable / enable a job not working

Viewed 1123

I'm trying to disable a job using "jenkinsapi" package in python. While I'm able to connect to the Jenkins server and get the list of jobs and status of the job, I am unable to enable / disable any job. I'm using the same script that's provided in the documentation but somehow jobs don't get disabled and no error gets thrown as well. Note: I have configured Jenkins to run on port 8081

from jenkinsapi.jenkins import Jenkins

def get_server_instance():
    jenkins_url = "http://<Jenkins_URL>:8081"
    server = Jenkins(jenkins_url, username="admin", password="password")
    return server

def get_job_details(job_name=None):
    server = get_server_instance()
    if job_name is None:
        for j in server.get_jobs():
            job_instance = server.get_job(j[0])
            print('Job Name:%s' % (job_instance.name))
            print('Job Description:%s' % (job_instance.get_description()))
            print('Is Job running:%s' % (job_instance.is_running()))
            print('Is Job enabled:%s' % (job_instance.is_enabled()))
    else:
        job_instance = server.get_job(job_name)
        print('Job Name:%s' % (job_instance.name))
        print('Job Description:%s' % (job_instance.get_description()))
        print('Is Job running:%s' % (job_instance.is_running()))
        print('Is Job enabled:%s' % (job_instance.is_enabled()))

def disable_job():
    server = get_server_instance()
    job_name = "RestartTest"
    if (server.has_job(job_name)):
        job_instance = server.get_job(job_name)
        job_instance.disable()
        print('Name:%s,Is Job Enabled ?:%s' %(job_name, job_instance.is_enabled()))

if __name__ == "__main__":
    get_job_details("RestartTest")
    disable_job()

Output of the program:

Job Name: RestartTest
Job Description: The job runs restart_test.sh
Is Job running: False
Is Job enabled: True
Name:EventsTesting,Is Job Enabled ?: True

Process finished with exit code 0

I'm expecting the Job Enabled as False and also the job status on the browser to show Disabled but nothing of that sort happens. My connection settings seem to be right (since I can connect to the server, get list of jobs, status, etc). Or is there a special setting to use for enabling / disabling jobs ?

Any help is greatly appreciated, thank you.

0 Answers
Related