如何使用 Artifactory Gradle 插件为构建信息设置 Username/Password?

How Do I Set The Username/Password For The Build Info Using The Artifactory Gradle Plugin?

我已经使用 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 的用户无权访问人工制品存储库,但人工制品块中的用户可以。

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

如何设置 username/password 以便使用具有权限的用户发布 build.info

您可以为 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.
的权限 OS 用户即 运行 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 = 'Whosebug'          //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 中,您会看到使用发布部分中指定的用户名部署的工件

以及 build-info JSON 文件

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

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