pranathi
pranathi

Reputation: 97

need to set condition from variables in azure pipelines

I setting up the variables at global level and value will be provided through variables before running pipeline, trying to set condition using variables but could not succeeded. below is my sample pipeline

  trigger
    - develop
  variables:
    stagename: $(stagename)

  stages:
  - stage: deploy
      - task: download artifact
        condition:  notin(variables($(stagename),(tst1,tst2)))

      - task: deploy2
        condition: notin(variables($(stagename),(tst1,tst2)))

the goal is to not to run above those two tasks if stagname equals to tst1 or tst2, should run in other cases.

Upvotes: 0

Views: 1037

Answers (1)

Walter
Walter

Reputation: 3058

You can refer to the following sample and it worked on my side:

trigger:
  - develop
stages:
- stage: deploy
  jobs:
  - job: Build
    steps:
    - task: PowerShell@2
      condition: notin(variables['stagename'],'tst1','tst2')
      inputs:
        targetType: 'inline'
        script: |
          Write-Host "Hello World"

You do not need to set variable at the pipeline root level. A variable set in the pipeline root level will override a variable set in the Pipeline settings UI. Here is the document about define variables and specify conditions.

Upvotes: 2

Related Questions