[英]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 个):
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)"
script
或pwsh
任务来回显或Write-Host
您想看到但不是的所有内容,如“ echo
pwsh: Write-Host "My var should be $(varname1)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.