1

我正在使用 jenkins api xml 创建新工作,查看工作,构建......它仅在 jenkins 不安全时才有效我正在使用此代码创建新工作

PostMethod postMethod = new PostMethod("localhost:8080/createItem?name="+projectName);
postMethod.setRequestHeader("Content-type","application/xml; charset=ISO-8859-1");
postMethod.setRequestBody(new FileInputStream(new File("/resources/config.xml")));
HttpClient client = new HttpClient();
returnCode = client.executeMethod(postMethod);
4

2 回答 2

3

您需要在请求中传递用户和 api 令牌。这是一个例子

于 2012-05-14T12:02:17.067 回答
0

这是一个ruby​​ 客户端,它通过其 API 帮助在 jenkins 中创建工作。虽然 Jenkins 只允许发布配置 XML,但此客户端接受参数作为 Hash 并构建 XML 并将其发布到 Jenkins。您可以通过提供有关 Jenkins 服务器信息及其凭据的信息来初始化客户端。

gem install jenkins_api_client

require "rubygems"
require "jenkins_api_client"

# Initialize the client by passing in the server information
# and credentials to communicate with the server
client = JenkinsApi::Client.new(
  :server_ip => "127.0.0.1",
  :username => "awesomeuser",
  :password => "awesomepassword"
)

# The following block will create 10 jobs in Jenkins
# test_job_0, test_job_1, test_job_2, ...
10.times do |num|
  client.job.create_freestyle(:name => "test_job_#{num}")
end

# The jobs in Jenkins can be listed using
client.job.list_all
于 2013-03-19T06:48:40.223 回答