正在尝试从Groovy向GitHub API发送请求:
def res = null
withCredentials([string(credentialsId: 'my-github-token', variable: 'GITAPITOKEN')]) {
withEnv(["REPO=${repo}", "PRID=${prId}", "LABEL=${label}"]) {
res = sh (script: 'curl -X PUT -H \\"Authorization: token $GITAPITOKEN\\" -d \\"{\\\\"labels\\\\":[\\\\"$LABEL\\\\"]}\\" https://api.github.com/repos/my-user/$REPO/issues/$PRID/labels', returnStdout: true).trim()
}
}
println("${res}")
它显示它执行以下操作:
curl -X PUT -H "Authorization: token****" -d "{\"labels\":[\"my-label\"]}" https://api.github.com/repos/my-user/my-repo/issues/1/labels
当我在本地运行此命令(包括所有转义字符)时,它可以完美地工作
但在Jenkins-这返回
curl: (6) Could not resolve host: token
curl: (6) Could not resolve host:****"
curl: (3) unmatched close brace/bracket in URL position:
my-label\"]}"
^
以及:
{
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest/reference/issues#set-labels-for-an-issue"
}
所以看起来标题转义不知何故不起作用-我错过了什么?
1条答案
按热度按时间jbose2ul1#
请尝试以下内容。