28

REST エンドポイントを呼び出すために、gitblit にポスト コミット フック (Groovy スクリプト) があります。このスクリプトでは、curl コマンドを実行しています。しかし、それは失敗するようです。コマンドラインから実行すると、curl コマンドは正常に機能します。

以下は私のグルーヴィーなスクリプトです。

#!/usr/bin/env groovy


def repoUrl= "https://gitblit.myhost.com/git/" + repository + ".git"
json='{"repository":{"url":"'+repoUrl+'"}}'

def response = "curl -v -k -X POST -H \"Content-Type: application/json\" -d '${json}' https://username:password@anotherhost.com:9443/restendpoint".execute().text
println response 

リポジトリは gitblit によってこのスクリプトに渡され、私はそれを確認しました。

誰かがこれを手伝ってくれますか。

4

4 に答える 4

23

curl コマンドのすべての文字列を配列に渡すことで、これを機能させることができました。以下は私がそれをした方法です。

def response = ["curl", "-k", "-X", "POST", "-H", "Content-Type: application/json", "-d", "${json}", "https://username:password@myhost.com:9443/restendpoint"].execute().text
于 2014-05-20T10:48:17.117 に答える
0

'running-forever' プロセスを回避するには (出力が 4096 バイトを超えると一部の Windows 環境で発生します)、初期サイズを ByteArrayOutputStream に追加します。

def initialSize = 4096
def out = new ByteArrayOutputStream(initialSize)
def err = new ByteArrayOutputStream(initialSize)
def proc = command.execute()
proc.consumeProcessOutput(out, err)
proc.waitFor()
于 2014-05-20T07:31:58.720 に答える