azure-devops - Azure 开发运营 : Populating secure file references with job matrix variables

标签 azure-devops continuous-integration devops

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

但是,当我在“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://learn.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."

最佳答案

Azure DevOps: Populating secure file references with job matrix variables

这是任务本身的限制。

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

enter image description here

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

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

enter image description here

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

Android apk signing: sign an unsigned apk using command line

关于azure-devops - Azure 开发运营 : Populating secure file references with job matrix variables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66231033/

相关文章:

azure-devops - Lerna Azure devOps 管道中分离的 git HEAD 错误

language-agnostic - 您如何在严格的 Scrum 车间中管理非面向用户的工作?

azure-devops - 使用 System.AccessToken 创建服务端点

ios - 如何从 Cordova 的 config.xml 配置 XCode 和客户端选项

使用 Semaphoreci 进行 Android 自动化集成测试。如何正确设置?

go - 是否可以在不运行 go install 的情况下更新本地软件包?

azure-devops - Azure DevOps 项目管道无法从不同项目中的工件源访问 NuGet 包

azure - 无法在独立区域路径之间移动Azure DevOps

azure - 链接到正确的团队服务帐户

unit-testing - 如何在测试失败时自动通知测试所有者?