31

Am using the curl command in PowerShell to post the comment in bit-bucket pull request page through a Jenkins job. I used the below PowerShell command to execute the curl command, but am getting the error mentioned below. Could anyone please help me on this to get it worked?

$CurlArgument="-u xxx@gmail.com:yyyy -X POST https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments --data content=success"
$CURLEXE='C:\Program Files\Git\mingw64\bin\curl.exe'
& $CURLEXE $CurlArgument

Error Details:

curl.exe : curl: no URL specified!
At line:3 char:1
+ & $CURLEXE $CurlArgument
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (curl: no URL specified!:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

curl: try 'curl --help' or 'curl --manual' for more information
Ansgar Wiechers
  • 184,186
  • 23
  • 230
  • 299

4 Answers4

17

Use splatting.

$CurlArgument = '-u', 'xxx@gmail.com:yyyy',
                '-X', 'POST',
                'https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments',
                '--data', 'content=success'
$CURLEXE = 'C:\Program Files\Git\mingw64\bin\curl.exe'
& $CURLEXE @CurlArgument
Ansgar Wiechers
  • 184,186
  • 23
  • 230
  • 299
13

In Powershell 3.0 and above there is both a Invoke-WebRequest and Invoke-RestMethod. Curl is actually an alias of Invoke-WebRequest in PoSH. I think using native Powershell would be much more appropriate than curl, but it's up to you :).

Invoke-WebRequest MSDN docs are here: https://technet.microsoft.com/en-us/library/hh849901.aspx?f=255&MSPPError=-2147217396

Invoke-RestMethod MSDN docs are here: https://technet.microsoft.com/en-us/library/hh849971.aspx?f=255&MSPPError=-2147217396

Jim Moyle
  • 607
  • 4
  • 11
  • 9
    Unfortunately Invoke_WebRequest is not even close to curl on the list of what you can do with curl. Simple `--verbose` flag is not available to see the details information about TLS connection, RAW http request and response. Am I missing something? – outcoldman Dec 11 '18 at 22:26
  • very useful, thank you! sometimes we get used-to of doing things in a particular way and forget to look for alternatives. – Praveen Tiwari Apr 19 '19 at 09:48
4

Or another option you could just call curl.exe using splatting as follows.

> curl.exe '-u', 'xxx@gmail.com:yyyy',
 '-X', 'POST',
 'https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments',                
 '--data', 'content=success'

To know where is curl.exe using this command Get-Command curl.exe

Other option is to delete aliases curl command with Invoke-WebRequest

To see and delete aliaes in PowerShell

>Get-Aliases
>Remove-Item alias:curl

Then just runing command without '.exe'

> curl '-u', 'xxx@gmail.com:yyyy',
 '-X', 'POST',
 'https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments',                
 '--data', 'content=success'

I hope this would helps.

Yugo Gautomo
  • 491
  • 5
  • 8
2

Instead of curl you can use this command:

(New-Object System.Net.WebClient).DownloadString("http://google.com")
blackgreen
  • 18,419
  • 19
  • 55
  • 71
Harsha
  • 21
  • 1