您可以为Gradle Artifactory plugin 配置两组 Artifactory 凭据:
用于工件解析的凭据
repositories {
jcenter()
maven {
url "http://repo.myorg.com/artifactory/my-repo" // The Artifactory (preferably virtual) repository to resolve from
credentials { // Optional resolver credentials (leave out to use anonymous resolution)
username = "username" // Artifactory user name
password = "password" // Password or API Key
}
}
}
用于部署工件和发布构建信息的凭据。
这是您需要用于部署工件并将信息构建到 Artifactory 的一组凭据。
您需要确保此用户具有 Repositories:Deploy 和 Builds:Deploy 的权限。
正在运行 gradle 的 OS 用户(gradle 用户)未用于身份验证,并且未被识别为 Artifactory 用户。但是,它被捕获为构建信息的一部分。
artifactory {
contextUrl = 'http://repo.myorg.com/artifactory' // The base Artifactory URL if not overridden by the publisher/resolver
publish {
contextUrl = 'http://repo.myorg.com/artifactory' //The base Artifactory URL for the publisher
//A closure defining publishing information
repository {
repoKey = 'my-repo' //The Artifactory repository key to publish to
username = 'stackoverflow' //The publisher user name
password = 'password' //The publisher password or API key
}
}
}
预期的行为是在运行以下命令时
./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 中,您将看到使用发布部分中指定的用户名部署的工件
以及构建信息 JSON 文件
在构建信息中,您将看到正在捕获 2 种用户类型:
- Artifactory 主体 - 这是用于部署构建信息的 Artifactory 用户
- Principal - 这是运行 gradle 构建的操作系统用户。此信息在构建信息 JSON 中被捕获为“主体”