Gradle发布尝试将RPM上传到Artifactory YUM repo两次,第二次失败,403

我正在尝试使用gradle和ivy-publish插件将一个RPM工件发布到Artifactory上的本地YUM仓库。 我遇到的问题是发布任务似乎尝试上传工件两次,第二次尝试失败(正确),HTTP状态代码为403.我通过身份validation的工件用户具有部署/缓存权限但不删除。

我的问题是为什么发布任务试图两次上传工件?

我包括我的gradle配置和下面的artifactory日志文件的摘录。 请注意,RPM是使用netflix os-package构建的

Gradle配置发布配置:

apply plugin: "ivy-publish" publishing { publications { rpm(IvyPublication) { artifact buildRpm.outputs.getFiles().getSingleFile() /* Ivy plugin forces an organisation to be set. Set it to anything as the pattern layout later supresses it from appearing in the filename */ organisation 'dummy' } } repositories { ivy { credentials { username 'username' password 'password' } url 'http://my.artifactory.com/artifactory/yum-dev-local/' layout "pattern", { artifact "${buildRpm.outputs.getFiles().getSingleFile().getName()}" } } } } 

要构建和发布工件,我执行以下操作(在工件上使用空的yum-local repo)

 ./gradlew clean buildRpm publish 

产生以下内容:

 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':my-artifact-service:publishRpmPublicationToIvyRepository'. > Failed to publish publication 'rpm' to repository 'ivy' > java.io.IOException: Could not PUT 'http://my.artifactory.com/artifactory/yum-dev-local/my-artifact-service-0.0.1-1.el7.x86_64.rpm'. Received status code 403 from server: Forbidden * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED 

Artifactory日志显示:

 2016-10-12 15:41:41,828 [http-nio-8081-exec-92] [INFO ] (oaeUploadServiceImpl:453) - Deploy to 'yum-dev-local:my-artifact-service-0.0.1-1.el7.x86_64.rpm' Content-Length: 4420 2016-10-12 15:41:41,842 [http-nio-8081-exec-64] [INFO ] (oaeUploadServiceImpl:299) - Deploy to 'yum-dev-local:my-artifact-service-0.0.1-1.el7.x86_64.rpm.sha1' Content-Length: 40 2016-10-12 15:41:41,850 [http-nio-8081-exec-90] [WARN ] (oarArtifactoryResponseBase:105) - Sending HTTP error code 403: Not enough permissions to overwrite artifact 'yum-dev-local:my-artifact-service-0.0.1-1.el7.x86_64.rpm' (user 'username' needs DELETE permission). 

最后一条日志行表示已再次发出PUT请求。 当我检查repo时,工件确实已成功上载,但是发布任务失败了。 有人能指出这里发生了什么吗?

版本:

 ------------------------------------------------------------ Gradle 2.14.1 ------------------------------------------------------------ Build time: 2016-07-18 06:38:37 UTC Revision: d9e2113d9fb05a5caabba61798bdb8dfdca83719 Groovy: 2.4.4 Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015 JVM: 1.8.0_73 (Oracle Corporation 25.73-b02) OS: Linux 4.3.5-300.fc23.x86_64 amd64 

我有类似的问题。

使用Gradle Artifactory插件解决。

其他答案中提供的示例配置:

https://stackoverflow.com/a/41238443/575350

发生这种情况是因为Gradle Ivy发布插件除了你的工件之外还会推送3个额外的文件 ,这些文件是:

  • 一个.sha1文件,其中包含工件的校验和
  • 一个.xml Ivy包文件,其中包含有关工件的信息
  • 上一个xml的.sha1文件

问题出在第一个.sha1文件中。 上传时,Artifactory / JFrog会认为您要覆盖以前上传的工件,该工件具有相同的名称,因此会出错。

您会认为只提供DELETE权限可以解决问题,但事实并非如此。 这样做只会用校验和.sha1文件替换以前上传的包,并且因为那种文件不是有效的.deb文件(在我的情况下,在你的.rpm中),当解压缩并生成Debian存储库结构时,它只会消灭你的原始神器,所以你将无法正常下载。

不幸的是,没有解决这个问题,因为没有办法告诉Ivy / Gradle不生成这些额外的文件,我知道( https://github.com/gradle/gradle/blob/master/subprojects/dependency -management / src / main / java / org / gradle / api / internal / artifacts / repositories / resolver / ExternalResourceResolver.java#L266 )

最后,我使用的解决方案是直接使用curl PUT到Artifactory / JFrog,这导致实际上更少的代码,但是额外的OS依赖(curl)。 如果您对此感到担心,可以使用Gradle HTTP库执行相同的操作:

 task uploadArtifactory(type: Exec) { def artifact = buildDeb.outputs.getFiles().filter { it.getAbsolutePath().endsWith ".deb" }.getSingleFile() commandLine "curl", "-X", "PUT", "https://$artifactoryUser:$artifactoryPassword@$artifactoryAccount.jfrog.io/$artifactoryAccount/$artifactoryRepo/pool/${project.name}_${version}_all.deb;deb.distribution={...};deb.component=main;deb.architecture=all", "--upload-file", artifact }