Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boolean variable as template parameter input

I am trying to use variables set with the Variables-Screen in Azure Pipelines as the input for a template parameter, but get the error:

Encountered error(s) while parsing pipeline YAML: /azure-pipelines.yml (Line: 18, Col: 25): The 'androidIsLibrary' parameter value '$(ANDROID_IS_LIBRARY)' is not a valid Boolean.

I built a template within Azure Pipelines. The template takes several Parameters. On of it looks like this:

parameters:
  - name: androidIsLibrary
    type: boolean
    default: false

I have set a variable inside a variable group ANDROID_IS_LIBRARY with value false.

I added the variable group inside my pipeline with the following statement:

variables:
  - group: adr-general-library

After that I included my template with parameter as shown here:

jobs:
  - template: job--android--build_and_deploy.yml@templates
    parameters:
      androidIsLibrary: $(ANDROID_IS_LIBRARY)

I can't find an example for this particular use case in the Azure DevOps documentation, so I hope somebody already faced that problem. I want to use that template with parameters but want to structure my parameters centralized in a variable group. There are a lot more variables and parameters, so it is not a solution to just put the variable definition directly into the templates. And I am also not able to change the template.

Thanks in advance

like image 252
Tim Dithmer Avatar asked Dec 03 '20 07:12

Tim Dithmer


1 Answers

I have encountered the exact same issue before.

The root cause of this issue is that the variable in variable group is string type instead of the boolean type.

So when you pass the variable value to parameter, it will show the error message.

I confirmed this issue with our product group and this is by design.

This is the reply:

at the point where we're processing ${{ templates }}, the contents of $(variables) are not processed. So indeed, "$(BooleanVar)" will never be a boolean. In fact, no variable can ever be a boolean - variables are always strings. This is working as designed.

For a workaround, you need to change the parameter type as string type in Template:

For example:

parameters:
  - name: androidIsLibrary
    type: string
    default: false

Then it will work.

Another method is that you could define the variable in the Main Yaml file and use this format ${{variables.variablename}}

For example:

variables:
  - name: one
    value: true

steps:
  - template: build.yml
    parameters:
      androidIsLibrary: ${{ variables.one }} 
like image 66
Kevin Lu-MSFT Avatar answered Oct 12 '22 17:10

Kevin Lu-MSFT