Why am i getting an error when declaring variables YAML

Viewed 81

I have the code as below which works fine

variables:
  - group: docker-settings

I need to add a variable to use in a condition so i insert the variable as below but then I get an error? If I remove -group :docker-settings it works, if I remove isMaster line instead it works but it doesnt like them both there? What am I doing wrong?

variables:
  - group: docker-settings
  isMaster: $[eq(variables['Build.SourceBranch'], 'refs/heads

I used these docs https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml

1 Answers

I used the name / value notation and fixed the value based on the MS example and set master instead of main. I guess this is what you want to have.

variables:
  - group: docker-settings
  - name: 'isMaster'
    value: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]

Microsoft example:

variables:
  staticVar: 'my value' # static variable
  compileVar: ${{ variables.staticVar }} # compile time expression
  isMain: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')] # runtime expression

steps:
  - script: |
      echo ${{variables.staticVar}} # outputs my value
      echo $(compileVar) # outputs my value
      echo $(isMain) # outputs True

Don't give up with yaml and Azure DevOps ;-)

Related