[Jenkins] Use python requests to programatically get and set Jenkins job configuration
2016-07-11 09:41
501 查看
Jenkins provided a very nice REST api to interact. In Python, we can use
The
Not there are two things you might need to pay attention to:
1. the url is
requestspackage. For simplicity, we are going to use password based authentication. For details on
requestspackage, please see its official documentation.
Get the job configuration
Get the configuration is real easy. Please replacejenkins_ip,
jenkins_port,
job_name,
username,
passwordwith your customized value.
import requests url = http://jenkins_ip:jenkins_port/job/job_name/config.xml r = requests.get(url, auth=('username', 'password')) config = r.text
The
configis an unicode xml string of the job configuration.
Set the job configuration
To modify the job configuration, you can post the modifiedconfigto the same url.
p = requests.post(url, data=config, auth=('username', 'password'))
Not there are two things you might need to pay attention to:
1. the url is
url = http://jenkins_ip:jenkins_port/job/job_name/config.xml[/code], noturl = http://jenkins_ip:jenkins_port/job/job_name[/code]
2. use thedataparameter, not thefilesparameter. Reason is listed here.
相关文章推荐
- python安装第三方插件出现的错误
- 爬虫笔记
- 一个程序学会python的流程控制
- mac 安装robotFramwork环境 以及wxPython 无法安装问题解决 (非常有用)
- Python collections模块实例讲解
- Python编写简单的HTML页面合并脚本
- Python中super()函数简介及用法分享
- python关于列表转为字典的两个小方法
- python常用代码片
- Python中super()函数简介及用法分享
- Python编写简单的HTML页面合并脚本
- Python中的异常处理相关语句基础学习笔记
- Python的SQLalchemy模块连接与操作MySQL的基础示例
- Python的requests网络编程包使用教程
- Windows中使用wxPython和py2exe开发Python的GUI程序的实例教程
- 使用Python的Tornado框架实现一个Web端图书展示页面
- 深入解析Python的Tornado框架中内置的模板引擎
- 浅析Python的web.py框架中url的设定方法
- Python - 数据库(pyMongo)
- 一句Python命令启动一个Web服务器