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':'未登录'})

前端页面代码:

{{ msglist }}
{% for job in li %} {% endfor %}
Job 类型 Job 名称 Job url Job 状态 Job 全名
{{ job.0 }} {{ job.1 }} {{ job.2 }} {{ job.3 }} {{ job.4 }}

页面显示效果

jenkins二次开发python-jenkins_第1张图片

jenkins二次开发python-jenkins_第2张图片

jenkins二次开发python-jenkins_第3张图片

jenkins二次开发python-jenkins_第4张图片

jenkins二次开发python-jenkins_第5张图片

 

你可能感兴趣的:(Django)