Ami*_*chi 18 groovy curl gitblit
我在gitblit中有一个post commit hook(一个groovy脚本)来调用REST端点.在这个脚本中,我正在执行curl命令.但似乎失败了.从命令行执行时,curl命令工作正常.
以下是我的groovy脚本.
#!/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
Run Code Online (Sandbox Code Playgroud)
存储库由gitblit传递给这个脚本,我已经验证了它.
有人可以帮我这个.
Wil*_*ill 21
我无法用你的例子重现你的问题,但我会尝试一个疯狂的猜测:
首先,使用列表execute()
版本,因此您没有令牌问题:
process = [ 'bash', '-c', "curl -v -k -X POST -H \"Content-Type: application/json\" -d '${json}' https://username:password@anotherhost.com:9443/restendpoint" ].execute().text
Run Code Online (Sandbox Code Playgroud)
其次,从过程中读取错误和输出:
process.waitFor()
println process.err.text
println process.text
Run Code Online (Sandbox Code Playgroud)
该err
可给出到底是怎么回事
Ami*_*chi 15
我能够通过将curl命令中的所有字符串传递给数组来实现此功能.以下是我的做法.
def response = ["curl", "-k", "-X", "POST", "-H", "Content-Type: application/json", "-d", "${json}", "https://username:password@myhost.com:9443/restendpoint"].execute().text
Run Code Online (Sandbox Code Playgroud)