如何在安全的情况下远程使用jenkins

时间:2012-05-14 11:33:02

标签: xml security api authentication jenkins

我正在使用jenkins api xml创建新工作,查看工作,构建...... 它只适用于詹金斯不安全的情况 我正在使用此代码创建新作业

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

2 个答案:

答案 0 :(得分:3)

您需要在请求中传递用户和api令牌。 Here's an example

答案 1 :(得分:0)

这是一个ruby client,它有助于通过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