Home > Mobile >  AZDO - Variable it's not assigned correctly?
AZDO - Variable it's not assigned correctly?

Time:01-18

I have the following strange problem with azure devops:

Let's assume that i have a branch called branch-playground and I have this pipeline.

First case with contains:

stages:
- stage: Stage_2
  displayName: 'test'
  variables:
  - name: customBranchName
    ${{ if startsWith(variables['Build.SourceBranch'], 'refs/heads/') }}:
      value: $[ replace(variables['Build.SourceBranch'], 'refs/heads/', '') ]
    ${{ if startsWith(variables['Build.SourceBranch'], 'refs/pull/') }}:
      value: $[ replace(variables['System.PullRequest.SourceBranch'], 'refs/heads/', '') ]
  jobs:
  - job: Test
    steps:
      - ${{ if contains('branch-playground', variables.customBranchName.value ) }}:
        - bash: echo "print"

In this case will be ok, the bash script will be executed.

BUT the strange thing is when i try to use eq.

... same as before...
  jobs:
  - job: Test
    steps:
      - ${{ if eq('branch-playground', variables.customBranchName.value ) }}:
        - bash: echo "print"

Now, this bash script it's not executed...

The log from Job execution:

Pool: Azure Pipelines
Image: ubuntu-latest
Agent: Azure Pipelines 2
Started: Today at 21:57
Duration: 5s

Job preparation parameters
Variables:
  customBranchName:
    Parsing expression: <replace(variables['Build.SourceBranch'], 'refs/heads/', '')>
    Evaluating: replace(variables['Build.SourceBranch'], 'refs/heads/', '')
    Expanded: replace('refs/heads/branch-playground', 'refs/heads/', '')
    Result: 'branch-playground'

Can anyone have any idea why it's happening this?

CodePudding user response:

The variable is variables.customBranchName, not variables.customBranchName.value.

CodePudding user response:

AZDO - Variable it's not assigned correctly?

You could try to use following syntax:

- bash: echo "print"
  condition: eq(variables.customBranchName, 'branch-playground')

Please check the detailed sample from the document:

Use a template parameter as part of a condition

steps:
- script: echo I did a thing
  condition: and(succeeded(), eq('${{ parameters.doThing }}', 'true'))
  •  Tags:  
  • Related