我想在每次生成新的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?”中有一些线索
原文链接:https://www.f2er.com/docker/532588.html例如,由于您生成了一个新的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"}]}'