Xml 当jenkins';很安全

Xml 当jenkins';很安全,xml,security,api,authentication,jenkins,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"); postMetho

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

您需要在请求中传递用户和api令牌

下面是一个通过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

它可以工作,但仅适用于构建如何使用“创建新作业”对其进行配置您确定您指定的用户可以创建新作业吗?我无法编写代码如何使用方法httposone附加config.xml文件那里的示例(用Groovy编写)正是这样做的。也许您应该尝试复制它,然后检查它发送的HTTP请求。然后了解如何使用您正在使用的HTTP API发送完全相同的请求。HttpPost post=new-HttpPost(“);post.setEntity(new-FileEntity(新文件(“C:/integrationContinue/src/main/resources/config.xml”),“application/xml;charset=ISO-8859-1”);HttpGet get1=new-HttpGet(“);HttpResponse response=client.execute(get1,context);没关系