python的Jenkins接口调用
来源:互联网 发布:电子书阅读器 知乎 编辑:程序博客网 时间:2024/06/05 04:45
本来非常喜欢偷懒
最好就是不干活那种
所以最近在研究把Jenkins模块集成起来
做成傻瓜界面这样就给他们用
本人Python搓望大神不要喷,多多指导
jenkins的Python模块模块安装
pip:pip install python-jenkins
easy_install:easy_install python-jenkins
使用:
class jenkins_tools(): def __init__(self): cf = get_conf() self.username = cf.get('jenkins', 'username') self.password = cf.get('jenkins', 'password') self.php_jenkins = '''#本屌自己的jenkins的conf文件 <project>#这里可以去抄jenkins的项目文件夹里面的配置文件 <actions/>#记得不要加xml头,源码哪里帮我们加了,自己加就是作死 <description></description>#项目需求不一样,配置文件也不一样,你们不要抄我的 <keepDependencies>false</keepDependencies> <properties> <hudson.model.ParametersDefinitionProperty> <parameterDefinitions> <hudson.model.StringParameterDefinition> <name>Branch</name> <description></description> <defaultValue>%s</defaultValue> </hudson.model.StringParameterDefinition> </parameterDefinitions> </hudson.model.ParametersDefinitionProperty> </properties> <scm class="hudson.scm.NullSCM"/> <canRoam>true</canRoam> <disabled>false</disabled> <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <triggers/> <concurrentBuild>false</concurrentBuild> <builders> <hudson.tasks.Shell> <command>xxxxxxx</command> </hudson.tasks.Shell> </builders> <publishers/> <buildWrappers/> </project> ''' self.java_newjenkins = '''#本屌的另外一个jenkins的conf文件 <project> <actions/> <description></description> <keepDependencies>false</keepDependencies> <properties> <hudson.model.ParametersDefinitionProperty> <parameterDefinitions> <hudson.model.StringParameterDefinition> <name>Branch</name> <description></description> <defaultValue>%s</defaultValue> </hudson.model.StringParameterDefinition> </parameterDefinitions> </hudson.model.ParametersDefinitionProperty> </properties> <scm class="hudson.scm.NullSCM"/> <canRoam>true</canRoam> <disabled>false</disabled> <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <triggers/> <concurrentBuild>false</concurrentBuild> <builders> <hudson.tasks.Shell> <command>xxxx</command> </hudson.tasks.Shell> </builders> <publishers/> <buildWrappers/> </project> ''' def __conn_jenkins_server(self, url): try: #获得一个jenkins的操作实例 server = jenkins.Jenkins(url, username=self.username, password=self.password) return server except Exception: logging.warning('login jenkins failed!') return None def create_project(self, host_ip, project_name, git_path, git_branch, url, environment): server = self.__conn_jenkins_server(url) if server: server.create_job(project_name, self.php_jenkins)#参数1写的是项目名称,参数2是xml文档 return True else: return None def project_built(self, url, project_name, git_branch):#这个函数作用是构建项目 server = self.__conn_jenkins_server(url) server.build_job(project_name, {'Branch': git_branch}) def check_project_exist(self, project_name, url):#这个函数是检查项目是否已经存在虽然写得很挫忘不要见怪 server = self.__conn_jenkins_server(url) name = server.get_job_name(project_name) if name is None: return False return True
详细可以看官方文档:http://python-jenkins.readthedocs.io/en/latest/api.html
1 0
- python的Jenkins接口调用
- PHP调用Jenkins接口的实现
- java调用Jenkins接口api
- jenkins api 接口json 调用
- salt的python接口调用
- Python调用OpenCV的接口
- jenkins的api调用python篇如何解除403
- jenkins的api调用python篇(二)
- jenkins的api调用python篇(三)秀代码
- jenkins api接口调用,触发工程
- LIBSVM在python下的接口调用
- php调用Python接口的方法
- python 调用C++接口的参数设置
- Jenkins + python(requests)做接口自动化测试
- Python 基于python+Testlink+Jenkins实现的接口自动化测试框架
- python 调用c++接口
- python 调用短信接口
- Python 调用 VLFeat 接口
- GitHub 排名前 100 的安卓、iOS项目简介
- 方法的递归调用
- RelativeLayout 布局
- 关于 SQLiteOpenHelper 的自创建数据库目录文件
- Node.js GET/POST请求
- python的Jenkins接口调用
- JQuery加载Json对象到form
- Hibernate 对象的几种状态
- 可选项
- JQuery的each方法详解
- 关于异或(XOR)的有趣应用
- tjut 1251
- if语句
- 控件内容遇到导航条出现偏移的情况