curlを使ってジョブを登録する方法は下部の更におまけに追記しました
前回GET系のリクエストを試したので今回はPOST系を試してみました
Rubyを使ってジョブの登録を実施しています
実行するRubyスクリプトと同じディレクトリに下部に記載したconfig.xmlを配置して
実行してください
また、サンプルが job_list というファイルに記載されている登録したいジョブ名分
登録するようになっているので job_list というファイルも作成してください
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'net/http'
require 'json'
endpoint = "http://localhost:8080"
File.open("job_list").each {|f|
path = "/createItem?name=" + f
uri = URI.parse(endpoint + path)
f = File.read("config.xml")
header = {
'Content-Type' =>'application/xml',
}
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = f
request.basic_auth 'username', 'password'
#http = Net::HTTP::Proxy('proxy_host_name', '8080').new(uri.host, uri.port)
http = Net::HTTP.new(uri.host, uri.port)
http.start do |h|
response = h.request(request)
puts response.status
end
}
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description>this job is created by api</description>
<keepdependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canroam>true</canRoam>
<disabled>false</disabled>
<blockbuildwhendownstreambuilding>false</blockBuildWhenDownstreamBuilding>
<blockbuildwhenupstreambuilding>false</blockBuildWhenUpstreamBuilding>
<buildwrappers>
<hudson.plugins.timestamper.TimestamperBuildWrapper plugin="timestamper@1.5.4"/>
</buildWrappers>
</project>
■おまけ CURLでジョブをビルドする方法
curl -X POST --user username:password http://localhost:8080/job/test_job/build
■おまけ CURLでパラメータ付きジョブをビルドする方法
curl -X POST --user username:password "http://localhost:8080/job/test_job/buildWithParameters?key1=value&key2=value"
■更におまけ CURLでジョブを作成する方法
curl -X POST --user username:password --data-binary "@config.xml" -H "Content-Type: text/xml" "http://localhost:8080/createItem?name=job_name"
■参考サイト
0 件のコメント:
コメントを投稿