1
votes

I am really struggling with some variables which I have in my variable group named '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.

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.

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? 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

1

1 Answers

3
votes

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.

If you're having problems with this, I recommend a couple of things (actually, 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)"
  2. Turn on system diagnostics when you run the pipeline and see if the output has any useful details
  3. Edit the pipeline through the portal - Pipelines - select your pipeline -> Edit. 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. Now, it won't give you variable values, but what it can do is give you clues as to possible format or declaration errors.