groovy中的curl请求抛出语法错误

groovy中的curl请求抛出语法错误,curl,jenkins,groovy,gitlab,gitlab-ci,Curl,Jenkins,Groovy,Gitlab,Gitlab Ci,我试图在groovy中执行一个curl请求,但它抛出语法错误: def pyString = "import json,sys;text=str(sys.stdin.read().strip());obj=json.loads(text);print ([dict['id'] for dict in obj if dict['name_with_namespace']=='prjs/myProj'])" def pyCmdArray = ["python", "-c", ${pyString}]

我试图在groovy中执行一个curl请求,但它抛出语法错误:

def pyString = "import json,sys;text=str(sys.stdin.read().strip());obj=json.loads(text);print ([dict['id'] for dict in obj if dict['name_with_namespace']=='prjs/myProj'])"
def pyCmdArray = ["python", "-c", ${pyString}]
def pyCmdOutput = pyCmdArray.execute()
println "Here you are: "
println pyCmdOutput.text()
def responseUrl = "https://abc.dev.sys/api/v3/projects?per_page=100"+pyCmdOutput.text()
def response = (curl -H "PRIVATE-TOKEN:yyyyyyyyyyyyyyyy" -H "Content-Type:application/json" ${responseUrl})
错误是:

    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 29: expecting ')', found 'PRIVATE-TOKEN:yyyyyyyyyyyyyyyy' @ line 29, column 27.
     def response = (curl -H "PRIVATE-TOKEN:yyyyyyyyyyyyyyyy" -H "Content-Type:application/json" ${responseUrl})

非常感谢您的帮助。

经过一点调整,我就可以完成这项工作了

def response = ["curl", "-H", "private_token:yyyyyyyyyyyyyyyy", "-H", "Content-Type:application/json", responseUrl].execute().text

为什么不使用
HttpUrlConnection
或HTTP库(如
httpbuilder ng
)来发出请求,而不是作为单独的进程执行
curl