Python Jenkins模块操作(持续集成-运维自动化)一

一、    安装python包
如果pip可以使用,请直接pip install python-jerkins, 因为我这里是rhel 6.8 手动将python 2.6.6 升级到了python 2.7.15。安装时使用了命了如下
pip install --trusted-host  pypi.org --trusted-host  files.pythonhosted.org python-jenkins
============丑陋的分割线===========
Collecting python-jenkins
Collecting six>=1.3.0 (from python-jenkins)
Collecting requests (from python-jenkins)
    100% |████████████████████████████████| 92kB 167kB/s 
Collecting multi-key-dict (from python-jenkins)
Collecting pbr>=0.8.2 (from python-jenkins)
    100% |████████████████████████████████| 102kB 106kB/s 
Collecting idna<2.7,>=2.5 (from requests->python-jenkins)
    100% |████████████████████████████████| 61kB 134kB/s 
Collecting urllib3<1.23,>=1.21.1 (from requests->python-jenkins)
    100% |████████████████████████████████| 133kB 161kB/s 
Collecting certifi>=2017.4.17 (from requests->python-jenkins)
    100% |████████████████████████████████| 153kB 48kB/s 
Collecting chardet<3.1.0,>=3.0.2 (from requests->python-jenkins)
    100% |████████████████████████████████| 143kB 98kB/s 
Installing collected packages: six, idna, urllib3, certifi, chardet, requests, multi-key-dict, pbr, python-jenkins
  Running  setup.py install for multi-key-dict ... done
Successfully installed certifi-2018.4.16 chardet-3.0.4 idna-2.6 multi-key-dict-2.0.3 pbr-4.0.3 python-jenkins-1.0.1 requests-2.18.4 six-1.11.0 urllib3-1.22
============丑陋的分割线===========
二、    测试
2.1 通过Jenkins API获取jekins的版本信息


import   jenkins

server   =   jenkins . Jenkins ( ' http://localhost:8080/jenkins ' ,   username = 'myuser' ,   password = 'mypassword' )
user   =   server . get_whoami ()
version   =   server . get_version ()
print ( 'Hello  %s  from Jenkins  %s '   %   ( user [ 'fullName' ],   version ))
2.2 获取jenkins当前所有job的信息

jobs = server . get_jobs ( view_name = 'View Name’ )
node_dict = json.dumps(jobs, sort_keys=True, indent=4, separators=(',', ': '), encoding='utf8',ensure_ascii=True)
print node_dict
[
    {
        "_class": "hudson.model.FreeStyleProject",
        "color": "blue",
        "fullname": "AllUnit-MonitorTest",
        "name": "AllUnit-MonitorTest",
    },
    {
        "_class": "org.jenkinsci.plugins.workflow.job.WorkflowJob",
        "color": "notbuilt",
        "fullname": "AllUnit-Pipline",
        "name": "AllUnit-Pipline",
    },
    {
        "_class": "hudson.model.FreeStyleProject",
        "color": "blue",
        "fullname": "AllUnit-PTest",
        "name": "AllUnit-PTest",
    },
    {
        "_class": "hudson.model.FreeStyleProject",
        "color": "blue",
        "fullname": "empty",
        "name": "empty",
        "url": " http://localhost:8081/jenkins/job/empty/ "
    }
]

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值