3

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 Answer 1

6

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.
7
  • Thank you for your awnser. Maybe I am doing something wrong but that's not valid and still, I don't see how I can get the $(key.alias) variable value I have updated my code so you have the full picture
    – Henkie85
    Mar 3, 2021 at 8:29
  • @Henkie85. From your code, you haven't used the variable format shared by WaitingForGuacamole. If you use the variable format in the answer, will it work? On the other hand, in Variable Group , is the variable a secret variable? Mar 3, 2021 at 8:49
  • 1
    I've clarified my answer above, @Kevin Lu, could you weigh in on whether I've gotten something wrong there, Henkie85, can you tell me if this helps you in any way? Mar 3, 2021 at 13:02
  • 1
    Perfect thank you for your patience and clear explanations .... I got it!
    – Henkie85
    Mar 3, 2021 at 13:38
  • 1
    No problem. I've gotten into a lot of trouble with YAML variables. Nice to pass along some solutions. Mar 3, 2021 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.