2012-05-14 87 views
1

我使用jenkins api xml來創建一個新的工作,看到工作,構建... 只有當jenkins不安全時纔有效 我使用此代碼來創建新的工作如何在安全的情況下遠程使用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); 

回答

3

您需要在請求中傳遞用戶和API標記。 Here's an example

+0

它的工作原理,但只針對如何建立與配置爲「創建新任務」 – Jhon

+0

你確定你要指定允許用戶創造新的就業機會? –

+0

我無法編寫代碼如何使用方法附加config.xml文件Httpost – Jhon

0

這是一個ruby client,它有助於通過API在jenkins中創建工作。儘管Jenkins只允許發佈配置XML,但該客戶端接受哈希參數並構建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 
相關問題