簡體   English   中英

如何在安全的情況下遠程使用jenkins

[英]how to use jenkins remotely when it's secure

我正在使用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);

您需要在請求中傳遞用戶和api令牌。 這是一個例子

這是一個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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM