15

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?

Michael B
  • 11,887
  • 6
  • 38
  • 74
  • I'm not sure what you are trying to achieve makes sense. you need a condition, basically and you are trying to emulate that condition with failure... which is probably not a great idea? why dont you catch the error in your script and output some data to the jobs down in the pipeline and make decision based on the value of the data passed? – 4c74356b41 Oct 31 '18 at 05:43
  • That is what I'm currently looking to do - my thinking was that if you can test on a job status, that shouldn't produce a failed build – Michael B Oct 31 '18 at 06:01
  • The particular problem seems contrived and doesn't entirely make sense, but the principle of being able to ignore a job failure is entirely useful. – Ed Randall Feb 12 '21 at 20:40
  • Does this answer your question? [Continue Azure Pipeline on failed task](https://stackoverflow.com/questions/56925979/continue-azure-pipeline-on-failed-task) – 030 Jan 31 '22 at 07:48

3 Answers3

31

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

laurisvr
  • 2,724
  • 6
  • 25
  • 44
My Digital life
  • 516
  • 5
  • 7
  • 6
    But will the build fail if this task fails? – Maximilian Jun 27 '19 at 19:13
  • 4
    With `continueOnError` a failing task will set the status to `SucceededWithIssues`. The build does not fail but succeeds and appears with a warning symbol. – Ben T Aug 25 '20 at 00:45
7

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!)

Michael B
  • 11,887
  • 6
  • 38
  • 74
  • Path filter works only for whole pipeline. And if you want to skip/add some step/job/stage you need to use workaround as above. – Krzysztof Madej Jun 23 '21 at 18:32
0

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

Jakub Pawlinski
  • 442
  • 3
  • 16