给予Azure DevOps管道访问权限以将gradle包发布到Azure DevOps工件源

ctrmrzij  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(250)

我正在建立一个共享代码库,并设法构建了工件,但我希望将发布移动到Azure管道。我正在尝试使用生成时可用的具有访问令牌的生成帐户(System.AccessToken)但我从Azure工件收到403错误。[Project]生成服务([Org])帐户被添加为源的贡献者。
我有一个build.gradle.kts文件,其中包含以下配置(替换了敏感信息):

publishing {
    publications {
        create<MavenPublication>("private") {
            groupId = "[groupId]"
            artifactId = "shared"
            version = "0.0.1"
            artifact("./build/libs/lib.jar")
        }
    }

    repositories {
        maven(url = "https://pkgs.dev.azure.com/[Org]/[Project]/_packaging/maven-private/maven/v1") {
            name = "maven-private"
            credentials {
                username = System.getenv("AZURE_DEVOPS_USER")
                password = System.getenv("AZURE_DEVOPS_ACCESS_TOKEN")
            }
        }
    }
}

Azure管道配置:

trigger:
  - main

pr: none

resources:
  - repo: self

stages:
  - stage: Build
    displayName: Build stage
    jobs:
      - job: Build
        displayName: Build
        pool:
          vmImage: 'ubuntu-latest'
        steps:
          - task: Gradle@2
            inputs:
              gradleWrapperFile: 'gradlew'
              workingDirectory: '$(Build.SourcesDirectory)'
              tasks: 'build'
              javaHomeOption: 'JDKVersion'
          - task: Gradle@2
            env:
              AZURE_DEVOPS_USER: "[Project] Build Service ([Org])"
              AZURE_DEVOPS_ACCESS_TOKEN: $(System.AccessToken)
            inputs:
              gradleWrapperFile: 'gradlew'
              workingDirectory: '$(Build.SourcesDirectory)'
              tasks: 'publish'
              javaHomeOption: 'JDKVersion'

发布步骤失败,出现以下错误:

Execution failed for task ':lib:publishPrivatePublicationToMaven-privateRepository'.
> Failed to publish publication 'private' to repository 'maven-private'
   > Could not PUT 'https://pkgs.dev.azure.com/[Org]/[Project]/_packaging/maven-private/maven/v1/[groupId]/shared/0.0.1/shared-0.0.1.jar'. Received status code 403 from server: Forbidden - User '[userId]' lacks permission to complete this action. You need to have 'ReadPackages'.

我不知道如何进行调试,有人有什么建议吗?

5cnsuln7

5cnsuln71#

对于错误“您需要拥有”ReadPackages ',“您应该输入Azure工件-〉您的源-〉源设置-〉权限。根据您的选择范围(组织范围或项目范围),

您应单击“添加用户/组”并搜索“项目集合生成服务({OrgName})”,然后添加为组织级别作用域源的参与者。
或者单击“添加用户/组”并搜索{Project Name} Build Service({Org Name}),然后添加为项目级范围内源的参与者。
请参阅Configure permissions文档中的详细信息。我希望这能帮上忙。

相关问题