jenkins二次开发python-jenkins

python-jenkins文档

python-jenkins Git

安装python-jenkins包

pip install python-jenkins

查询所有job后端代码:

class JenkinsListView(View):
    def get(self, request):
        jtitle = '未登录:Jenkins'
        if request.session.get('j_login', None):
            jip_port = request.session['jip_port']
            jtitle = '已登录:' + jip_port
        return render(request, 'jenkins/jenkinslist.html', {'jtitle': jtitle})

    def post(self, request):
        jtitle = '未登录:Jenkins'
        if request.session.get('j_login', None):
            jip_port = request.session['jip_port']
            jtitle = '已登录:' + jip_port
            juname = request.session['juname']
            jpswd = request.session['jpswd']
            try:
                server = jenkins.Jenkins(jip_port, juname, jpswd)
                jobs = server.get_all_jobs()
                li = []
                for job in jobs:
                    li.append([])
                    li[jobs.index(job)].append((job['_class']))
                    li[jobs.index(job)].append((job['name']))
                    li[jobs.index(job)].append((job['url']))
                    li[jobs.index(job)].append((job['color']))
                    li[jobs.index(job)].append((job['fullname']))
            except Exception as e:
                return render(request, 'jenkins/jenkinslist.html', {'jtitle': jtitle, 'msglist': '查不到job信息'})
            return render(request, 'jenkins/jenkinslist.html', {'jtitle': jtitle, 'li': li})
        return render(request, 'jenkins/jenkinslist.html', {'jtitle': jtitle, 'msgquery':'未登录'})

前端页面代码:

<form action="/yw/jenkins_list/" method="post">
    <button type="submit" class="btn btn-success">查询所有job</button>
    <span style="color: red" >{{ msglist }}</span>
</form>
<div class="table-responsive">
    <table class="table no-margin">
    <thead>
        <tr>
            <th>Job 类型</th>
            <th>Job 名称</th>
            <th>Job url</th>
            <th>Job 状态</th>
            <th>Job 全名</th>
        </tr>
    </thead>

    <tbody>
        {% for job in li  %}
        <tr>
            <td>{{ job.0 }}</td>
            <td>{{ job.1 }}</td>
            <td>{{ job.2 }}</td>
            <td>{{ job.3 }}</td>
            <td>{{ job.4 }}</td>
        </tr>
        {% endfor %}
    </tbody>
    </table>
</div>

页面显示效果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值