gpt4 book ai didi

rest - 使用 REST API 远程创建 Jenkins 作业

转载 作者:行者123 更新时间:2023-12-05 00:40:26 26 4
gpt4 key购买 nike

我无法远程创建作业(REST API + Postman),我试试

发布:

http://localhost:8080/createItem?name=NEWJOB

http://localhost:8080/job/NEWJOB/build

总是有 403 错误(GET 方法有效)。

在这里我看到我需要为 POST 创建 config.xml :

https://issues.jenkins-ci.org/browse/JENKINS-9410?focusedCommentId=204821&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-204821

我不明白如何创建此配置?我需要这个配置吗?如何远程创建jenkins Job?

最佳答案

我需要几个步骤:

1) 获取

http://localhost:8080/crumbIssuer/api/json 

+header 授权.....................基本YWRtaW46YWRtaW4=

Value of Authorization field was created when I put in login and password(admin,admin in my case).

在这个查询之后我看到了下一个:

{
"_class": "hudson.security.csrf.DefaultCrumbIssuer",
"crumb": "2ad62df85d23d4c65a25c0b33fb0ef61",
"crumbRequestField": "Jenkins-Crumb"
}

2)下一步->创建config.xml

我只是手动从另一个 Jenkins 工作(名为测试)中获取它:

GET http://localhost:8080/job/test/config.xml

+header header 授权........基本YWRtaW46YWRtaW4=

3)创建工作:

POST http://10.14.48.107:8080/createItem?name=NEWJOBNAME

+header 授权........基本YWRtaW46YWRtaW4=

+header Content-Type ......... text/xml

+header Jenkins-Crumb ......... 2ad62df85d23d4c65a25c0b33fb0ef61

I take this header name and value from 1st query crumb

+ body ->原始->

<project>
<actions/>
<description/>
<keepDependencies>false</keepDependencies>
<properties>
<com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github@1.29.0">
<displayName/>
</com.coravy.hudson.plugins.github.GithubProjectProperty>
</properties>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders/>
<publishers/>
<buildWrappers/>
</project>

在这一步之后,我没有任何答案,但工作是远程创建的!

关于rest - 使用 REST API 远程创建 Jenkins 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49051397/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com