【问题标题】:How Do I Set The Username/Password For The Build Info Using The Artifactory Gradle Plugin?如何使用 Artifactory Gradle 插件设置构建信息的用户名/密码?
【发布时间】:2020-10-05 14:17:26
【问题描述】:

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

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

我正在运行 gradle 的用户无权访问工件存储库,但工件块中的用户可以。

似乎build.info 正在使用 gradle 用户而不是 build.gradle 中的用户发布到工件。

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

【问题讨论】:

  • 什么是“Gradle 用户”?你是怎么配置的?
  • “gradle user”是运行./gradlew的用户

标签: gradle artifactory


【解决方案1】:

您可以为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 种用户类型:

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

【讨论】:

  • 您基本上重复了我在问题中所说的内容。这并没有解决与构建信息相关的实际问题,该构建信息位于工件存储库的单独位置。
  • @opticyclic 我更新了答案以包含更多详细信息。我相信它正在回答“如何设置用户名/密码以便使用具有权限的用户发布 build.info?”的问题?
猜你喜欢
  • 2021-02-02
  • 2021-11-28
  • 2016-11-03
  • 1970-01-01
  • 1970-01-01
  • 2017-04-12
  • 2016-07-01
  • 2015-11-27
  • 2016-09-07
相关资源
最近更新 更多