Azure devops Azure DevOps:使用作业矩阵变量填充安全文件引用

Azure devops Azure DevOps:使用作业矩阵变量填充安全文件引用,azure-devops,continuous-integration,devops,Azure Devops,Continuous Integration,Devops,在上下文中,我尝试使用Azure构建管道来构建多种风格的Android应用程序。每种风格都有自己独立的签名密钥库,所有这些密钥库都存储在库中我的“安全文件”中 但是,当我在“android签名”任务期间尝试取消引用$(Keystore)变量时,它似乎无法识别该变量是否存在,而是尝试查找名为“$(Keystore)”的文件 我做错什么了吗?这似乎应该奏效 经过清理的示例如下所示: # Android # Build your Android project with Gradle. # Add s

在上下文中,我尝试使用Azure构建管道来构建多种风格的Android应用程序。每种风格都有自己独立的签名密钥库,所有这些密钥库都存储在库中我的“安全文件”中

但是,当我在“android签名”任务期间尝试取消引用$(Keystore)变量时,它似乎无法识别该变量是否存在,而是尝试查找名为“$(Keystore)”的文件

我做错什么了吗?这似乎应该奏效

经过清理的示例如下所示:

# Android
# Build your Android project with Gradle.
# Add steps that test, sign, and distribute the APK, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/android

trigger:
- feat/ci-setup

pool:
  vmImage: 'macos-latest'

variables:
  ${{ if startsWith(variables['build.sourceBranch'], 'refs/heads/feat/') }}: 
    Branch_Type: 'feature'
  ${{ if startsWith(variables['build.sourceBranch'], 'refs/heads/hotfix/') }}: 
    Branch_Type: 'hotfix'
  ${{ if startsWith(variables['build.sourceBranch'], 'refs/heads/release/') }}: 
    Branch_Type: 'release'
  ${{ if eq(variables['Branch_Type'], 'release') }}: 
    Configuration: 'release'
    ConfigurationCC: 'Release'
  ${{ if ne(variables['Branch_Type'], 'release') }}: 
    Configuration: 'debug'
    ConfigurationCC: 'Debug'

jobs:
- job: Build
  variables:
  - group: android_keystores
  strategy:
    maxParallel: 2
    matrix:
      Flavor_1:
        AppFlavor: '1'
        AppFlavorCC: '1'
        Keystore: 'flavor1.keystore'
        KeyAlias: 'flavor1'
        KeystorePass: '$(flavor1_storepass)'
        KeyPass: '$(flavor1_keypass)'
      Flavor_2:
        AppFlavor: '2'
        AppFlavorCC: '2'
        Keystore: 'flavor2.keystore'
        KeyAlias: 'flavor2'
        KeystorePass: '$(flavor2_storepass)'
        KeyPass: '$(flavor2_keypass)'

  steps:
  - task: Gradle@2
    inputs:
      workingDirectory: ''
      gradleWrapperFile: 'gradlew'
      gradleOptions: '-Xmx3072m'
      publishJUnitResults: false
      tasks: 'assemble$(AppFlavorCC)$(ConfigurationCC)'

  - task: AndroidSigning@3
    displayName: Signing .apk
    inputs:
      apkFiles: 'app/build/outputs/apk/$(AppFlavor)/$(Configuration)/*.apk'
      apksign: true
      apksignerKeystoreFile: '$(Keystore)'
      apksignerKeystorePassword: '$(KeystorePass)'
      apksignerKeystoreAlias: '$(KeyAlias)'
      apksignerKeyPassword: '$(KeyPass)'
      zipalign: true

  - task: Bash@3
    displayName: Move APK to Artifact Folder
    continueOnError: true
    inputs:
      targetType: 'inline'
      script: |
        mv \
        app/build/outputs/apk/$(AppFlavor)/$(Configuration)/*.apk \
        $(Build.ArtifactStagingDirectory)/$(ArtifactName)/

  - task: PublishBuildArtifacts@1
    displayName: Publish Build Artifacts
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: 'Blueprint-Build'
      publishLocation: 'Container'
但当管道运行时,我被告知:

There was a resource authorization issue: "The pipeline is not valid. Job Build: Step AndroidSigning input keystoreFile references secure file $(Keystore) which could not be found. The secure file does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz."

您缺少下载安全文件的步骤。与变量组不同,您需要显式下载它们,以便通过安全文件名进行访问

您需要在提取安全文件的步骤中添加类似于下面的示例任务的内容。然后,您将通过名称\u参数访问您的安全文件。secureFilePath

          - task: DownloadSecureFile@1
            displayName: "Download Keyfile 1"
            name: "YOUR_SECUREFILE_NAME"
            inputs:
                secureFile: keyfile1
          - task: AndroidSigning@3
            displayName: Signing .apk
            inputs:
                apkFiles: 'app/build/outputs/apk/$(AppFlavor)/$(Configuration)/*.apk'
                apksign: true
                apksignerKeystoreFile: '$(YOUR_SECUREFILE_NAME.secureFilePath)'
                apksignerKeystorePassword: '$(KeystorePass)'
                apksignerKeystoreAlias: '$(KeyAlias)'
                apksignerKeyPassword: '$(KeyPass)'
                zipalign: true
Azure DevOps:使用作业矩阵变量填充安全文件引用

这是任务本身的一个限制

当我们用经典模式测试时,我们会发现,密钥库文件选项的值无法手动输入,我们只能通过下拉菜单选择某个文件:

这就是为什么它似乎无法识别这是一个存在的变量,而是尝试查找名为“
$(Keystore)
”的文件的原因

要解决此问题,您可以将任务版本从
3
更改为
1
,支持手动输入:

作为另一种解决方案,您还可以使用命令行对*.apk进行签名:


谢谢,我将尝试添加DownloadSecureFile任务,但根据Android签名任务的文档,它似乎会直接检查您的库。我怀疑问题来自于它试图在实际解析矩阵参数之前触发文件下载,但我将在这里报告我的结果。我可能错了。不幸的是,DownloadSecureFile任务的问题与AndroidSigning任务的问题相同,当我引用Keyfile作为变量时管道无效。作业蓝图\u生成:步骤签名\u密钥库输入secureFile引用找不到的安全文件$(密钥库)。`我试图避免为管道作业的每个实例下载每个密钥库,但是如果我不能为此使用策略矩阵值,那么我就必须为每种风格都有一个任务,这违背了使用策略的目的。那太糟糕了。真是糟糕透了,很抱歉解决方案没能奏效。顺便说一句,我能想到的另一件事是,如果密钥文件未被授权在管道中使用。但是,在这种情况下,在管道运行之前,通常会提示您在管道本身内授予访问权。瘸的我想我必须完成所有的构建,然后有单独的任务对它们进行签名。无论如何,谢谢你的帮助。这个问题有更新吗?如果答案能给你一些帮助,请随时告诉我。只是提醒一下。是的,我在下面接受了你的答案,因为尽管我走了不同的路线,但这似乎解决了我的问题。这是一个关于更改任务版本的好建议,我可以试试。我选择的解决方法是将签名作为发布管道的一部分,因为在发布过程中,我必须为每种口味做单独的工作。