def connect(credentials): """ Since a user can have simple authentication with a single user/password or define a set of IRC nick to Jenkin's users with API tokens, this helper untangles this and returns a connection. If no authentication is configured, just a connection is returned with no authentication (probably read-only, depending on Jenkins settings) """ connection = Jenkins( credentials['url'], username=credentials['username'], password=credentials['password'], ) connection.password = credentials['password'] # try an actual request so we can bail if something is off connection.get_info() return connection
def connect(credentials): """ Since a user can have simple authentication with a single user/password or define a set of IRC nick to Jenkin's users with API tokens, this helper untangles this and returns a connection. If no authentication is configured, just a connection is returned with no authentication (probably read-only, depending on Jenkins settings) """ connection = Jenkins( credentials['url'], username=credentials['username'], password=credentials['password'], ) connection.password = credentials['password'] # try an actual request so we can bail if something is off connection.get_info() return connection
# coding: utf-8 __author__ = 'xP' from jenkins import Jenkins jenkins_object = Jenkins('http://127.0.0.1:8080') print(jenkins_object.get_info())
# -*- coding: utf-8 -*- # @Time : 2019-07-26 20:23 # @Author : Eylaine # @File : __init__.py from jenkins import Jenkins from settings import JENKINS_URL as URL from settings import JENKINS_PASSWORD as PASSWORD from settings import JENKINS_USERNAME as USERNAME from settings import JENKINS_JOB_NAME as JOB_NAME """python-jenkins模块的使用和常用方法""" jenkins = Jenkins(URL, USERNAME, PASSWORD) # 获取所有的jobs all_jobs = jenkins.get_all_jobs() # 根据job name获取info,返回json job_info = jenkins.get_job_info(JOB_NAME) # 最后一次build的信息,包含num和url last_build = job_info["lastBuild"] # 最后一次build的number,int类型 NUMBER = last_build["number"] build_info = jenkins.get_build_info(JOB_NAME, NUMBER) info = jenkins.get_info() # 运行日志 console_text = jenkins.get_build_console_output(JOB_NAME, NUMBER)