我正在尝试使用在 Jenkins 任务中运行的 Groovy 脚本从 Artifactory 存储库中删除工件。该脚本在我的存储库的给定路径中收集与时间戳匹配的所有工件,然后尝试从存储库中删除它们。
脚本的有趣部分如下所示:
def base.url = 'http://name:port'
def repo = 'my-repo'
def path = 'my-path'
def artifact = 'my-artifact'
def url.to.delete = base.url + '/artifactory/' + repo + '/' + path + '/' + artifact
print "url.to.delete = " + url.to.delete
def server = new RESTClient(base.url)
server.auth.basic('user', 'password')
def resp = server.delete(path: url.to.delete)
删除语句导致此异常
groovyx.net.http.HttpResponseException: Forbidden
at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:240)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:508)
at groovyx.net.http.RESTClient.delete(RESTClient.java:196)
at groovyx.net.http.RESTClient$delete.call(Unknown Source)
at Artifactory$_deleteartifactsWithTimestamps_closure2.doCall(hudson4086512083232103441.groovy:87)
at Artifactory.deleteartifactsWithTimestamps(hudson4086512083232103441.groovy:80)
at Artifactory$deleteartifactsWithTimestamps.callCurrent(Unknown Source)
at Artifactory.deleteSnapshots(hudson4086512083232103441.groovy:32)
at Artifactory$deleteSnapshots.call(Unknown Source)
at hudson4086512083232103441.run(hudson4086512083232103441.groovy:170)
计算出的 url.to.delete 似乎是正确的——如果我从日志中复制它并将其粘贴到浏览器的地址字段中,则工件将被毫无问题地下载。可以从 Groovy 脚本访问 Artifactory - 收集路径的工件的 GET 使用相同的数据可以正常工作。
我使用 Artifactory 2.6.4(免费版!)、带有 http-builder-0.6.jar 的 Groovy 2.1.1。
谢谢你的帮助!
坦率