【问题标题】:How to POST an updated config.xml using Jenkins REST API?如何使用 Jenkins REST API 发布更新的 config.xml?
【发布时间】:2017-09-08 09:00:52
【问题描述】:

我想编写一个 groovy 脚本来使用 Jenkins REST API 批量更新我的作业配置。但我对它的 API 文档 (http://localhost:8080/jenkins/job/my_job_name/api/) 感到很困惑。

获取/更新 config.xml

要以编程方式获取 config.xml,请点击此 URL。您还可以将更新的 config.xml 发布到相同的 URL[http://localhost:8080/jenkins/job/my_job_name/config.xml] 以编程方式更新作业的配置。

如何将 xml 文件发布到上述 url?

【问题讨论】:

    标签: rest jenkins hudson


    【解决方案1】:

    下面的 curl 命令对我有用。

    curl --user $USER:$API_TOKEN -X POST http://localhost:8080/job/test/config.xml -H 'Content-Type: application/xml' --data-binary "@mymodifiedlocalconfig.xml"
    

    【讨论】:

      【解决方案2】:

      我尝试了 cURL,它成功了。

      curl -F "file=@updated_config.xml" "http://localhost:8080/jenkins/job/my_job_name/config.xml"  
      

      注意:您需要在 Jenkins 配置中关闭“防止跨站点请求伪造漏洞”。

      【讨论】:

        【解决方案3】:
        curl -X POST -H 'Content-Type: application/octet-stream' http://<ip>/job/<job name>/config.xml --user uname:upass --data-binary @./test.xml
        

        许多答案设置 Content-Type: application/xml,但它在我的 Jenkins 中不起作用。我尝试设置 Content-Type: application/octet-stream 并成功运行。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-02-08
          • 2018-07-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-01-17
          • 1970-01-01
          相关资源
          最近更新 更多