加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

python-如何以编程方式在jenkins作业配置页面中设置github repo

发布时间:2020-12-16 03:23:19 所属栏目:安全 来源:网络整理
导读:我想在每次生成新的Jenkins容器时通过代码在http://host-ip:8080/job/my_project/configure jenkins页面中设置Github存储库URL. 我读到可以用python-jenkins的reconfig_job function替换config.xml来完成. 好吧,我该怎么做? 最佳答案 您在“ How can I upda

我想在每次生成新的Jenkins容器时通过代码在http://host-ip:8080/job/my_project/configure jenkins页面中设置Github存储库URL.

我读到可以用python-jenkins的reconfig_job function替换config.xml来完成.

好吧,我该怎么做?

最佳答案
您在“ How can I update a jenkins job using the api?”中有一些线索

例如,由于您生成了一个新的Jenkins容器,因此您可以docker cp将一个更新的config.xml添加到该容器中(该作业的正确路径)

(当在git bash中运行时,OP Kostas Demiris确认in the comments可以工作)

您也可以使用Jenkins API libraries之一,但请检查是否为simple curl is enough first

#Get the current configuration and save it locally
curl -X GET http://user:password@jenkins.server.org/job/myjobname/config.xml -o mylocalconfig.xml

#Update the configuration via posting a local configuration file
curl -X POST http://user:password@jenkins.server.org/job/myjobname/config.xml --data-binary "@mymodifiedlocalconfig.xml"

updated Jenkins doc mentions(用于仅更新现有配置作业中的一个参数):

Simple example - sending "String Parameters":

curl -X POST JENKINS_URL/job/JOB_NAME/build 
  --data token=TOKEN 
  --data-urlencode json='{"parameter": [{"name":"id","value":"123"},{"name":"verbosity","value":"high"}]}'

Another example - sending a "File Parameter":

curl -X POST JENKINS_URL/job/JOB_NAME/build 
  --user USER:PASSWORD 
  --form file0=@PATH_TO_FILE 
  --form json='{"parameter": [{"name":"FILE_LOCATION_AS_SET_IN_JENKINS","file":"file0"}]}'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读