使用 REST 远程创建 Jenkins 作业 API

Create Jenkins Job remotely with REST API

我无法远程创建 Job(REST API + Postman),我尝试

POST:

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

当我 :

获取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>

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