Michael B
Michael B

Reputation: 12228

Azure DevOps job ignore failure

I have the following in my azure-pipelines.yml

jobs:
- job: TestifFolder1Exists
  pool:
    vmImage: 'ubuntu-16.04'

  steps:
  - bash: git log -1 --name-only | grep -c Folder1
    failOnStderr: false

- job: Folder1DoesntExist
  pool:
    vmImage: 'ubuntu-16.04'
  dependsOn: TestifFolder1Exists
  condition: failed() 

- job: Folder1DoesExist
  pool:
    vmImage: 'ubuntu-16.04'
  dependsOn: TestifFolder1Exists
  condition: succeeded() 

I am trying to test whether a folder has had a change made, so I can publish artifacts from that directory.

The problem I am having is that if there isn't anything written to the folder, the script fails with a Bash exited with code '1'. (this is what I want) which in turn makes the whole build fail.

If I add continueOnError then the following jobs always run the succeeded job.

How can I let this job fail, without it failing the entire build?

Upvotes: 16

Views: 39433

Answers (3)

Jakub Pawlinski
Jakub Pawlinski

Reputation: 482

In powershell task there is ignoreLASTEXITCODE property, that turns off propagation of exit code back to pipeline, so you can i.e. analyse it in next task. Not sure why it was not provided for bash. https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/powershell?view=azure-devops

Upvotes: 1

My Digital life
My Digital life

Reputation: 543

There is a option called continueOnError. It's set to false by default. Change this to true and your task won't stop the job from building.

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/tasks?view=azure-devops&tabs=yaml#controloptions

Upvotes: 34

Michael B
Michael B

Reputation: 12228

I didn't figure out how to ignore a failed job, but this is how I solved this particular problem

jobs:
- job: TestifFolder1Exists
  pool:
    vmImage: 'ubuntu-16.04'

  steps:
  - bash: |
      if [ "$(git log -1 --name-only | grep -c Folder1)" -eq 1 ]; then 
        echo "##vso[task.setVariable variable=Folder1Changed]true"
      fi
  - bash: echo succeeded
    displayName: Perform some task
    condition: eq(variables.Folder1Changed, 'true') 

(although it turns out that Azure Devops does what I was trying to create here already - path filters triggers!)

Upvotes: 8

Related Questions