user941238
user941238

Reputation: 650

Hudson Remote API gives 400 error when Invoke-RestMethod POST called from Powershell v3

I want to script out the creation of a Hudson job with Powershell (Hudson version 3.0.1-b2). Looks like this should be easy, from Configure or Create hudson job automatically and http://technet.microsoft.com/en-us/library/hh849971.aspx (Invoke-RestMethod). But lo, I am a powershell beginner:

Invoke-RestMethod -Uri "http://localhost:hudsonPort/createItem?name=jobName" -Body config.xml -Method Post -ContentType "text/xml"

In the browser, localhost:hudsonPort brings me to Hudson, and I'm running the above command from a directory containing config.xml, which is an existing Hudson job's configuration file. I've also tried preparing the body argument beforehand with $body = cat config.xml and supplying that to the Invoke-RestMethod command.

Either way, I get a 400 bad request error. What's wrong with the request? It looks pretty good to me.

Upvotes: 0

Views: 607

Answers (1)

Keith Hill
Keith Hill

Reputation: 201672

I believe you need to provide the contents of the XML file e.g. -Body (Get-Content config.xml -Raw).

Upvotes: 2

Related Questions