Theodosis
Theodosis

Reputation: 954

Azure Pipelines condition doesnt work as it should

I started working with my YAML file to run some tasks and push a docker image in docker hub IFF branch is equal to master else run some tests and verify that tests passed without problem I have this YAML file right now

trigger:
  - master


jobs:


  - job: runTests
    pool:
      vmImage: 'Ubuntu-16.04'
      condition: ne(variables['Build.SourceBranch'], 'refs/heads/master'))
    steps:
      - task: Maven@3
        inputs:
          mavenPomFile: 'pom.xml'
          # according to: https://github.com/MicrosoftDocs/vsts-docs/issues/3845,
          # maven options should go to goals instead, as mavenOptions is for jvm options
          mavenOptions: '-Xmx3072m'
          javaHomeOption: 'JDKVersion'
          jdkVersionOption: '1.11'
          jdkArchitectureOption: 'x64'
          publishJUnitResults: true
          testResultsFiles: '**/surefire-reports/TEST-*.xml'
          goals: 'verify -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true --batch-mode --show-version'
  - job: ifBranchIsMaster
    pool:
      vmImage: 'Ubuntu-16.04'
      condition: eq(variables['Build.SourceBranch'], 'refs/heads/master'))
    steps:
      - task: Maven@3
        inputs:
          mavenPomFile: 'pom.xml'
          # according to: https://github.com/MicrosoftDocs/vsts-docs/issues/3845,
          # maven options should go to goals instead, as mavenOptions is for jvm options
          mavenOptions: '-Xmx3072m'
          javaHomeOption: 'JDKVersion'
          jdkVersionOption: '1.11'
          jdkArchitectureOption: 'x64'
          publishJUnitResults: true
          testResultsFiles: '**/surefire-reports/TEST-*.xml'
          goals: 'verify -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true --batch-mode --show-version -Ddocker.username=$(DOCKER_HUB_USER) -Ddocker.password=$(DOCKER_HUB_PASS) docker:push'

so basically as we see in the documentation right here says exactly what condition to use in what situation and the

condition: eq(variables['Build.SourceBranch'], 'refs/heads/master'))

works as it should when the branch is master run this steps else skip

but this condition

condition: ne(variables['Build.SourceBranch'], 'refs/heads/master'))

runs even in the master so what did I read wrong I want to skip the first tests if the branch is master cause if I don't skip the first one I basically run the tests same tests 2 times

Upvotes: 0

Views: 312

Answers (1)

4c74356b41
4c74356b41

Reputation: 72151

your indentation is wrong, it should be this:

  - job: runTests
    condition: ne(variables['Build.SourceBranch'], 'refs/heads/master'))
    pool:
      vmImage: 'Ubuntu-16.04'

Upvotes: 1

Related Questions