【问题标题】:Create Jenkins Job remotely with REST API使用 REST API 远程创建 Jenkins 作业
【发布时间】:2018-03-01 14:04:38
【问题描述】:

我无法远程创建作业(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?

【问题讨论】:

  • 尝试使用 Jenkins CLI
  • @minas 我想从 java 发送 REST 查询是不可能的
  • 为什么不可能?
  • @minas 这是我组织的问题,所以我们只需要使用 rest api

标签: rest jenkins jenkins-job-builder


【解决方案1】:

我需要几个步骤:

1) 获取

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

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

授权字段的值是在我输入登录时创建的,并且 密码(管理员,在我的例子中是管理员)。

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

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

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

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

获取http://localhost:8080/job/test/config.xml

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

3)创建工作:

发布http://10.14.48.107:8080/createItem?name=NEWJOBNAME

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

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

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

我从第一个查询碎片中获取这个标题名称和值

+身体->原始->

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

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

【讨论】:

    猜你喜欢
    • 2020-05-27
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多