gpt4 book ai didi

gradle - 如何使用 Artifactory Gradle 插件为构建信息设置用户名/密码?

转载 作者:行者123 更新时间:2023-12-03 04:54:10 24 4
gpt4 key购买 nike

我已经设置了使用 gradle 发布到 artifactory 的用户名和密码,但是,在发布 build.info 时构建失败。

artifactory {
publish {
contextUrl = 'http://localhost:8081/artifactory'
repository {
repoKey = "libs-snapshot-local"
username = "user"
password = "pass"
maven = true
}
defaults {
publications = ('mavenJava')
}
}
}

与我一起运行 gradle 的用户无权访问 artifactory 存储库,但 artifactory block 中的用户可以。

似乎 build.info 正在与 gradle 用户而不是 build.gradle 中的用户一起发布到 artifactory。

如何设置用户名/密码,以便使用具有权限的用户发布 build.info

最佳答案

您可以为 Gradle Artifactory plugin 配置两组 Artifactory 凭证:

用于 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 和发布构建信息的凭据。这是您在将 Artifactory 和构建信息部署到 Artifactory 时需要使用的一组凭据。
您需要确保此用户具有 Repositories:Deploy 和 Builds:Deploy 的权限。
运行 gradle 的操作系统用户(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 和构建信息将被部署到 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 中,您将看到使用发布部分中指定的用户名部署的 Artifactory

enter image description here

以及构建信息 JSON 文件

enter image description here

在构建信息中,您将看到正在捕获 2 种用户类型:

  1. Artifactory principal - 这是用于部署构建信息的 Artifactory 用户
  2. Principal - 这是运行 gradle 构建的操作系统用户。此信息作为“主体”在构建信息 JSON 中捕获

enter image description here

关于gradle - 如何使用 Artifactory Gradle 插件为构建信息设置用户名/密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64210458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com