Python jenkinsapi - 禁用/启用不起作用的作业

时间:2017-07-13 15:52:05

标签: python jenkins jenkins-api

我试图使用" jenkinsapi"来禁用作业在python中打包。虽然我能够连接到Jenkins服务器并获取作业列表和作业状态,但我无法启用/禁用任何作业。我使用的是文档中提供的相同脚本,但某些工作不会被禁用,也不会抛出任何错误。注意:我已将Jenkins配置为在端口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()

计划的输出:

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

我希望Job Enabled为False,并且浏览器上的作业状态显示为Disabled,但不会发生这种情况。我的连接设置似乎是正确的(因为我可以连接到服务器,获取作业列表,状态等)。或者是否有用于启用/禁用作业的特殊设置?

非常感谢任何帮助,谢谢。

0 个答案:

没有答案