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



我正在尝试在 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

最新更新