【发布时间】:2021-01-28 15:14:53
【问题描述】:
在 Jenkinsfile 中,我试图找出 Artifactory 中是否存在文件。 Jenkins 代理在 Windows 上运行。 所以我将How to get response code from curl in a jenkinsfile 和How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)? 2 个stackoverflow 解决方案组合成以下代码:
try {
env.CHECK_URL = bat(returnStdout: true, script: "curl -s -o /dev/null -w \"%%{http_code}\" \"https://myartifactory.com/myfile.exe\"")
} catch (Exception e) {
echo 'Exception occurred: ' + e.toString()
}
echo "URL Response: ${env.CHECK_URL}"
我希望 env.CHECK_URL 包含 200(已找到)或 404(未找到)。但是 http 代码 200 被写入输出,而不是变量。 curl 返回错误 23 (Failed writing body)。
上述函数的输出:
C:\Jenkins\workspace\my_jenkins>curl -s -o /dev/null -w "%{http_code}" "https://myartifactory.com/myfile.exe"
200
[Pipeline] echo
Exception occurred: hudson.AbortException: script returned exit code 23
[Pipeline] echo
URL Response: null
任何建议如何解决它?或者如果文件存在于 Artifactory 中,Jenkinsfile 的另一种方法来查找 ouf?
【问题讨论】:
标签: curl jenkins-pipeline artifactory