0

I have an issue with azure pipelines. I'm trying to create a template so I can push multiple instances like dev and qa. Since Azure doesn't support using variable groups in the template I'm passing them to the template using paramethers. The issue is that I'm getting this error:

##[warning]Unable to expand variable 'TOKEN_QA'. A cyclical reference was detected.

Any ideas how to resolve this issue?

name: ...

trigger: none

variables:
- group: api-mgmt-...-qa
- name: token_qa
  value: $(TOKEN_QA)
- name: project_qa
  value: $(PROJECT_ID_QA)
- group: api-mgmt-...-dev
- name: token_dev
  value: $(TOKEN_DEV)
- name: project_dev
  value: $(PROJECT_ID_DEV)
 
pool:
  name: '...'
  vmImage: ubuntu-latest

stages:
  - stage: "DEV_Deploy"
    dependsOn: []
    jobs:
      - template: ./api-publish_deployment.yml
        parameters:
          env: "dev"
          token: ${{variables.token_dev}}
          project: ${{variables.project_dev}}

  - stage: "QA_Deploy"
    dependsOn: 
    - "DEV_Deploy"
    jobs:
      - template: ./api-publish_deployment.yml
        parameters:
          env: "qa"
          token: ${{variables.token_qa}}
          project: ${{variables.project_qa}}

parameters:
  - name: env
    type: string
    values:
      - dev
      - qa
  - name: token
    type: string
  - name: project
    type: string
  
jobs:
  - job: Publish_Api
    displayName: Publish API on ${{parameters.env}}
    steps:
      - checkout: self
        path: $(Build.Repository.Name)

      - task: GoTool@0
        displayName: Install Go $(goVersion)
        inputs:
          version: '1.19'

      - task: Bash@3
        displayName: Publish API
        env:
          IDENTIFIER: ...
          BASEURL: ...
          PROJECT: ${{ parameters.project }}
          STAGE: ${{ parameters.env }}
          TOKEN: ${{ parameters.token }}
        inputs:
          targetType: 'inline'
          script: |
            echo $IDENTIFIER $BASEURL $PROJECT $STAGE
            stackit-api-manager project publish \
             --identifier $IDENTIFIER \
             --baseURL $BASEURL \
             --project $PROJECT \
             --stage $STAGE \
             --token $TOKEN \
             --oas config/... .yml

      - script: go clean -modcache
        displayName: Cleanup Go mod folder
  • *Since Azure doesn't support using variable groups in the template* What do you mean? Variable groups are supported in YAML. – Daniel Mann Mar 30 '23 at 14:28
  • https://stackoverflow.com/questions/60912733/azure-pipelines-yaml-unexpected-value-variables . This thread explains what I mean. "You can't have variables in a template that is included as a stage, job or step template (i.e. included below a stages, jobs or steps element in a pipeline). You can only use variables in a variable template." – Атанас Чолаков Mar 30 '23 at 14:57

1 Answers1

2

You have circular references.

- name: token_qa
  value: $(TOKEN_QA)

This is saying "define a variable named token_qa with the value set to the contents of the token_qa variable". In terms of another programming language, it's like saying string foo = foo; in C# or Java.

If those variables are defined in your variable group, you don't need to redefine them.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120