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

我想在每次生成新的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"}]}'

相关文章

最近一直在开发Apworks框架的案例代码,同时也在一起修复Apw...
最近每天都在空闲时间努力编写Apworks框架的案例代码WeText。...
在《Kubernetes中分布式存储Rook-Ceph部署快速演练》文章中,...
最近在项目中有涉及到Kubernetes的分布式存储部分的内容,也...
CentOS下Docker与.netcore(一) 之 安装 CentOS下Docker与.ne...
CentOS下Docker与.netcore(一) 之 安装 CentOS下Docker与.ne...