如何使用简单的Java程序在jenkins中创建作业

时间:2014-01-28 12:15:15

标签: java jenkins-cli

我是Jenkins的新手,我想用Java创建一份新工作。任何人都可以帮助我吗? 有哪些API需要使用,是否有示例代码?

1 个答案:

答案 0 :(得分:1)

我正在使用Jenkins REST API

客户端代码(JAX-WS)

Response result = ClientBuilder.newClient()
        .target("http://myserver/jenkins")
        .path("createItem")
        .queryParam("name", "myNewJob")
        .request()
        .accept(MediaType.APPLICATION_JSON)
        .post(Entity.entity(jobConfigurationXml(), 
                MediaType.APPLICATION_XML));

作业配置

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description></description>
  <keepDependencies>false</keepDependencies>
  <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>