您可以为Gradle Artifactory插件配置两组Artifactory凭据:
用于解析构件的凭据
repositories {
jcenter()
maven {
url "http://repo.myorg.com/artifactory/my-repo"
credentials {
username = "username"
password = "password"
}
}
}
部署工件和发布构建信息所使用的凭据。
这是您在将工件和构建信息部署到Artifactory时需要使用的凭据。
您需要确保此用户具有Repositories:Deploy和Builds:Deploy的权限。
运行gradle(gradle用户)的操作系统用户未用于身份验证,也不被识别为Artifactory用户。然而,它作为构建信息的一部分被捕获。
artifactory {
contextUrl = 'http://repo.myorg.com/artifactory'
publish {
contextUrl = 'http://repo.myorg.com/artifactory'
repository {
repoKey = 'my-repo'
username = 'stackoverflow'
password = 'password'
}
}
}
预期行为是在运行以下命令时:
./gradlew clean artifactoryPublish
构建产物和构建信息将被部署到Artifactory。
[pool-17-thread-1] Deploying artifact: http://127.0.0.1:8081/artifactory/libs-snapshot-local/gradle-example-minimal/1.0-SNAPSHOT/gradle-example-minimal-1.0-SNAPSHOT.jar
[pool-17-thread-1] Deploying artifact: http://127.0.0.1:8081/artifactory/libs-snapshot-local/gradle-example-minimal/1.0-SNAPSHOT/gradle-example-minimal-1.0-SNAPSHOT.pom
> Task :artifactoryDeploy
Deploying build descriptor to: http://127.0.0.1:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://127.0.0.1:8081/artifactory/webapp/builds/gradle-example-minimal/1602276439713
BUILD SUCCESSFUL in 903ms
7 actionable tasks: 7 executed
在Artifactory中,您将看到使用发布部分指定的用户名部署的构件。
![enter image description here](https://istack.dev59.com/tjJ5S.webp)
除了构建信息的JSON文件
![enter image description here](https://istack.dev59.com/LqJmM.webp)
在构建信息中,您将看到捕获了两种用户类型:
- Artifactory主体 - 这是用于部署构建信息的Artifactory用户
- 主体 - 这是运行gradle构建的操作系统用户。此信息以“主体”形式捕获在构建信息JSON中
![enter image description here](https://istack.dev59.com/71gSd.webp)
./gradlew
的用户。 - opticyclic