2016-07-01 15 views
28

私はJenkinsでREST APIを使用して新しいジョブを作成しています。 私はカールCMDラインの下にしようとしたが、彼らはエラーJenkins REST API Create job

curl -i -X POST --user "admin:<API token>" --data-binary "@C:\mylocalconfig.xml" -H "Content-Type: text/xml" http://localhost:8080/createItem?name=NewJob 

curl -X POST -u <username>:<pass> -H "Content-Type:application/xml" -d "@C:\mylocalconfig.xml" "http://localhost:8080/createItem?name=AA_TEST_JOB3" 

エラー投げている:デフォルトで


HTTP/1.1 403 No valid crumb was included in the request 
Date: Fri, 01 Jul 2016 05:25:59 GMT 
X-Content-Type-Options: nosniff 
Content-Type: text/html; charset=ISO-8859-1 
Cache-Control: must-revalidate,no-cache,no-store 
Content-Length: 360 
Server: Jetty(9.2.z-SNAPSHOT) 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
<title>Error 403 No valid crumb was included in the request</title> 
</head> 
<body><h2>HTTP ERROR 403</h2> 
<p>Problem accessing /createItem. Reason: 
<pre> No valid crumb was included in the request</pre></p><hr><i><small>Power 
ed by Jetty://</small></i><hr/> 
</body> 
</html> 

+0

[可能な重複](http://stackoverflow.com/questions/23497819/trigger-parameterized-build-with-curl-and-crumb) – rdupz

答えて

50

ジェンキンスはCSRF Protectionone-click attacksを防止する有効になっています。リクエストを呼び出すには、資格情報を使用して/crumbIssuer/api/xmlからクラムを取得し、リクエストに含める必要があります。たとえば:

CRUMB=$(curl -s 'http://USER:[email protected]:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') 

は、あなたは(あなたのヘッダーにクラムを含むことによって)ジョブを作成することができます動作しません

curl -X POST -H "$CRUMB" "http://USER:[email protected]:8080/createItem?name=NewJob" 

上記の場合は、お使いのクラム(echo $CRUMB)をチェックしたりしてcurlを実行します-u USER:TOKEN

詳細については、Running jenkins jobs via command lineを参照してください。

+0

私はこれを行うと、私は 「エラーを取得 ないのContentタイプヘッダーセット ' – battey

+0

2017年の時点で、これは完全な例です:[コマンドライン経由でのジェンキンジョブの実行](http://www.inanzzz.com/index.php/post/jnrg/running-jenkins-build-via-コマンドライン) – BentCoder

関連する問題