完美工作curl命令失败时,在groovy脚本中执行 [英] Perfectly working curl command fails when executed in a groovy script
问题描述
我在gitblit中有一个post提交钩子(一个groovy脚本)来调用一个REST端点。在这个脚本中,我正在执行curl命令。但它似乎失败。
I have a post commit hook (a groovy script) in gitblit to invoke a REST endpoint. In this script I am executing a curl command. But it seems to fail. The curl command works fine when executed from the commandline.
以下是我的groovy脚本。
Following is my groovy script.
#!/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传递给此脚本,并已验证。
repository is passed by gitblit to this script and I have verified it.
有人可以帮我解决这个问题。
Can somebody help me with this.
推荐答案
我会尝试一个疯狂的猜测:
I couldn't reproduce your problem with your example, but i will try a wild guess:
首先,使用列表 execute()
版本,有令牌问题:
First, use the list execute()
version, so you don't have problems with tokens:
process = [ 'bash', '-c', "curl -v -k -X POST -H \"Content-Type: application/json\" -d '${json}' https://username:password@anotherhost.com:9443/restendpoint" ].execute().text
其次,从流程中读取错误和输出:
Second, read both error and output from the process:
process.waitFor()
println process.err.text
println process.text
err
可能会显示发生的情况
The err
may give out what is going on
这篇关于完美工作curl命令失败时,在groovy脚本中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!