简体   繁体   English

未从 Azure Devops 管道中的变量组中的变量获取任何值

[英]Not getting any values from variables in variable groups in Azure Devops pipeline

I am really struggling with some variables which I have in my variable group named 'android-pipeline'.我真的在为我的变量组中名为“android-pipeline”的一些变量而苦苦挣扎。 Inside this variable group, I have some variables with values.在这个变量组中,我有一些带有值的变量。 But when I am running the pipeline it cannot read the values inside my variable group.但是当我运行管道时,它无法读取我的变量组中的值。 :( :(

Example: Inside the variable group, I have a variable called $(key.alias) I am trying to get this value which is behind the variable, see my code below.示例:在变量组中,我有一个名为 $(key.alias) 的变量,我正在尝试获取该变量后面的值,请参见下面的代码。

I think something is wrong with the syntax (or the way I am using it), but I cannot find the right syntax for using my $(key.alias) variable.我认为语法(或我使用它的方式)有问题,但我找不到使用 $(key.alias) 变量的正确语法。

Also, inside the variable group I have made sure that All pipelines have access to this Variable group.此外,在变量组内,我确保所有管道都可以访问此变量组。 Can someone, please tell me how I can get the value behind the $(key.alias) variable and use this in a task?有人可以告诉我如何获取 $(key.alias) 变量背后的值并在任务中使用它吗? I tried to follow many guides, but none are clear enough for me or not working我尝试遵循许多指南,但没有一个对我来说足够清楚或不工作

variables:
  group: android-pipeline
  buildConfiguration: 'Release'

stages:
stage: Publish
    dependsOn: Build
    displayName: Sign Apps 
    jobs:

        - task: AndroidSigning@3
          displayName: Android App signing
          inputs:
            apkFiles: '**/*.apk'
            apksignerKeystoreFile: '$(androidKeyStore)'
            apksignerKeystorePassword: '********'
            apksignerKeystoreAlias: '$(key.alias)'
            apksignerKeyPassword: '*******'
            apksignerArguments: --out $(outputDirectory)/app.release.apk
            zipalign: true

Since you're mixing groups and inline variables, you may need to change this from a mapping to a sequence, as in:由于您正在混合组和内联变量,因此您可能需要将其从映射更改为序列,如下所示:

variables:
- group: android-pipeline
- name: buildConfiguration
  value: Release

Normally when you declare variables, you can do them like a mapping, or hashtable, of name/value pairs:通常,当您声明变量时,您可以像名称/值对的映射或哈希表一样执行它们:

variables
  var1: value1 # note there's no dash at the beginning of the line
  var2: value2
  var3: value3
  # etc

When you want to use a group, you have to change your syntax a little, so that the parser doesn't think you want to create a variable named "group" - you turn it into a sequence, or array:当你想使用一个组时,你必须稍微改变你的语法,这样解析器就不会认为你想创建一个名为“组”的变量——你把它变成一个序列或数组:

variables
- group: groupname1 # note there's a dash at the beginning of the line
- group: groupname2
  # etc

Here's the final wrinkle - once you've gone from the first format to the second (mapping to sequence), you have to declare new variables that are local to your file in the "sequence" style:这是最后的问题 - 一旦你从第一种格式转到第二种格式(映射到序列),你必须以“序列”样式声明文件本地的新变量:

variables
- group: groupname1 # note there's a dash at the beginning of the line
- name: varname1
  value: value1
- name: varname2
  value: value2
  # etc

You reference the variable further down in your pipeline the same way, with $(varname1) syntax.您可以使用$(varname1)语法以相同的方式在管道中进一步引用该变量。

If you're having problems with this, I recommend a couple of things (actually, 3):如果您对此有疑问,我建议您做几件事(实际上是 3 个):

  1. Use script or pwsh tasks to echo or Write-Host everything you want to see but aren't, as in " pwsh: Write-Host "My var should be $(varname1)"使用scriptpwsh任务来回显或Write-Host您想看到但不是的所有内容,如“ echo pwsh: Write-Host "My var should be $(varname1)"
  2. Turn on system diagnostics when you run the pipeline and see if the output has any useful details运行管道时打开系统诊断,查看 output 是否有任何有用的详细信息
  3. Edit the pipeline through the portal - Pipelines - select your pipeline -> Edit.通过门户编辑管道 - 管道 - select 您的管道 -> 编辑。 Then, from the ellipsis menu in the top right of the page, select "Download full YAML" - this will give download what the compiler would create.然后,从页面右上角的省略号菜单中,select “下载完整的 YAML” - 这将下载编译器将创建的内容。 Now, it won't give you variable values, but what it can do is give you clues as to possible format or declaration errors.现在,它不会为您提供变量值,但它可以为您提供有关可能的格式或声明错误的线索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure DevOps 发布管道变量值未更新 - Azure DevOps Release Pipeline Variable Values are not updating 从 azure devops 管道更新变量组 - update variable group from azure devops pipeline 从管道 B 访问管道 A 的变量... Azure Devops - Access pipeline A´s variables from pipeline B... Azure Devops 如何从 Azure Devops 变量组中调用 Terraform 文件中的环境变量? - How to call Environment Variables from Azure Devops Variable Groups in Terraform files? 如何限制项目参与者删除 Azure Devops 中的变量组/变量 - How to restrict Project Contributers to delete Variable Groups/Variables in Azure Devops Azure DevOps 管道触发变量 - Azure DevOps pipeline trigger variables Azure devops 变量组在 powershell - Azure devops variable groups in powershell 使用来自 DevOps 发布管道的多个变量标记 Azure 资源 - Tag an Azure Resource using multiple variables from a DevOps Release Pipeline Azure DevOps 发布管道 - 如何使用 Azure Powershell 在管道中的变量中设置和传递值 - Azure DevOps Release Pipeline - How to set and pass values in variables in pipeline with Azure Powershell Azure DevOps 管道 - 带管道变量的条件表达式 - Azure DevOps Pipeline - condition expression with pipeline variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM