简体   繁体   English

使用rest更新jenkins作业的Git存储库

[英]Update Git repository of a jenkins jobs using rest

我从用户那里输入作业名称,git存储库,git用户名和密码作为输入。我能够使用rest创建一个jenkins作业,但是我无法设置该作业的git存储库路径。因此如何与一个使用休息的git存储库?

Maybe you can use the workaround presented in " How to create a job using the REST API and cURL " 也许您可以使用“ 如何使用REST API和cURL创建作业 ”中介绍的解决方法

First: 第一:

Create a job using the UI . 使用UI创建作业 This job can be used to create a base config that can be used to create new jobs. 该作业可用于创建可用于创建新作业的基本配置。

To retrieve the job config.xml that you made via the UI, to use for creating new jobs: 要检索通过UI创建的作业config.xml ,以用于创建新作业:

curl -X GET http://developer:developer@localhost:8080/job/test/config.xml -o mylocalconfig.xml

Obviously, replace: 显然,更换:

  • developer:developer with your username:password 开发人员:使用您的用户名:密码的开发人员
  • localhost:8080 with your Jenkins URL 本地主机:8080和您的Jenkins URL
  • test with the name of the job that you created via the UI 使用通过UI创建的作业名称进行测试

Then, 然后,

use this config to create a new job: 使用此配置创建新作业:

curl -s -XPOST 'http://developer:developer@localhost:8080/createItem?name=yourJobName' --data-binary @mylocalconfig.xml -H "Content-Type:text/xml"

The idea is to: 这个想法是:

  • use mylocalconfig.xml (from step 1) as a template, 使用mylocalconfig.xml (来自步骤1)作为模板,
  • change the content of mylocalconfig.xml with the right git repo path to use in Step 2 and create a job using the Remote access API . 使用正确的git repo路径更改mylocalconfig.xml的内容以在步骤2中使用,并使用远程访问API创建作业。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM