【问题标题】:Azure DevOps: Populating secure file references with job matrix variablesAzure DevOps:使用作业矩阵变量填充安全文件引用
【发布时间】:2021-02-16 19:36:28
【问题描述】:

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

但是,当我尝试在“android 签名”任务期间取消引用 $(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."

【问题讨论】:

  • 这个问题有更新吗?如果答案能给你一些帮助,请随时告诉我。只是提醒this
  • 是的,我在下面接受了您的回答,因为即使我选择了不同的路线,看起来也可以解决我的问题。

标签: azure-devops continuous-integration devops


【解决方案1】:

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

这是任务本身的限制。

我们在Classic模式下测试时发现,Keystore file选项的值无法手动输入,只能通过下拉菜单选择某个文件:

这就是为什么它似乎没有认识到这是一个存在的变量,而是试图找到一个名为“$(Keystore)”的文件。

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

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

Android apk signing: sign an unsigned apk using command line

【讨论】:

  • 这是一个关于更改任务版本的好技巧,我可以试试。我选择的解决方法是仅将签名作为发布管道的一部分进行,因为在发布期间无论如何我都必须为每种风格分配单独的工作。
【解决方案2】:

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

您需要在提取安全文件的步骤中添加类似于以下示例任务的内容。然后,您将通过 NAME_PARAMETER.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

【讨论】:

  • 谢谢,我会尝试添加 DownloadSecureFile 任务,但根据 Android Signing 任务的文档,它似乎直接检查您的库。 docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/… 我怀疑问题出在它试图在实际解析矩阵参数之前触发文件下载,但我会在这里报告我的结果。我可能是错的。
  • 不幸的是,当我将 Keyfile 作为变量引用时,DownloadSecureFile 任务的问题与 AndroidSigning 任务的问题相同。 ``` 管道无效。 Job Blueprint_Build:Step Signing_Keystore 输入secureFile 引用了找不到的安全文件$(Keystore)。 ``` 我试图避免必须为管道作业的每个实例下载 每个 密钥库,但如果我不能为此使用策略矩阵值,我将不得不有一个任务对于每种口味,这违背了使用策略的目的。这会很糟糕。
  • 这太糟糕了,抱歉解决方案没有成功。顺便说一句,我能想到的唯一另一件事是密钥文件是否未被授权在管道中使用。但是,在这种情况下,通常会提示您在管道运行之前授予其内部访问权限。
  • 嗯。瘸。我想我必须完成所有构建然后有单独的任务来签署它们。无论如何,感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2018-05-06
  • 1970-01-01
  • 2014-11-19
  • 2013-05-27
  • 1970-01-01
  • 2014-11-21
  • 2021-07-29
  • 1970-01-01
相关资源
最近更新 更多