Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to expand variable '...' . A cyclical reference was detected

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
like image 696
Атанас Чолаков Avatar asked Sep 02 '25 13:09

Атанас Чолаков


2 Answers

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.

like image 107
Daniel Mann Avatar answered Sep 05 '25 16:09

Daniel Mann


After having this issue, i found out that the problem was with the naming, the name and value cannot be the same even if one is with upper case and other with lower.

like image 36
Yehonatan Blumenfeld Avatar answered Sep 05 '25 17:09

Yehonatan Blumenfeld