2016-10-18 22 views
2

PowerShellでcurlコマンドを使用して、Jenkinsジョブを通じてビットバケットプルリクエストページにコメントを投稿しています。 curlコマンドを実行するために、以下のPowerShellコマンドを使用しましたが、下記のエラーが発生しています。誰もがこれを働かせるために私を助けてくれませんか?PowerShellでcurlコマンドを使用するには?

$CurlArgument="-u [email protected]: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 

エラーの詳細:

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
+0

申し訳ありませんが、カールの経験を持っていないが、なぜあなたは、組み込みを使用していませんPowerShellの 'Invoke-WebRequest' cdmletでは? –

+0

@MartinBrandl、それを認識していない、私はそれについて点検し、あなたに知らせるでしょう。 –

答えて

2

使用splatting

$CurlArgument = '-u', '[email protected]: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 
+0

以下のエラーが発生しています。 + CategoryInfo:NotSpecified:(%Total ... Time Current:String)[]、RemoteException + FullyQualifiedErrorId:NativeCommandError –

+0

これは 'curl'ステータス出力です。それを抑制するパラメータ '-s'を追加してください。 –

+0

$ CurlArgument = '-s'、 '-u'、 '[email protected]:yyyy'、 '-X'、 'POST'、 'https://xxx.bitbucket.org/1.0/repositories/ abcd/efg/pull-requests/2229/comments '、 ' --data '、' content = success ' –

1

Powershell 3.0以降では、Invoke-WebRequestとInvoke-RestMethodの両方があります。 Curlは実際にPoSHのInvoke-WebRequestのエイリアスです。私はネイティブのPowershellを使うことは、カールよりもはるかに適切だと思いますが、それはあなた次第です。

を呼び出し、WebRequestクラスMSDNのドキュメントはここにある: https://technet.microsoft.com/en-us/library/hh849901.aspx?f=255&MSPPError=-2147217396

起動-RestMethod MSDNのドキュメントはここにある: https://technet.microsoft.com/en-us/library/hh849971.aspx?f=255&MSPPError=-2147217396

関連する問題