0

I have an azure-pipelines.yml file with many jobs. There are no dependsOn: in the azure-pipelines.yml file, so that the jobs can run in parallel.

If any job fails, I would like Azure to not start any queued jobs. I don't want to cancel any running jobs, nor cancel the whole pipeline.

I don't see a way to do this using a condition, but maybe I am missing something. Another possibility would be to have each job create a pipeline artifact file indicating its success or failure status, and then each job would look to see if any other job had failed. This seems to require starting the job, and I would prefer that the job not start at all.

Can you suggest a way to achieve my goal?

mernst
  • 7,437
  • 30
  • 45
  • 1
    If you want to rely on status of other job/jobs you have to add this job/those jobs to dependsOn and add proper condition (which be default is succedded), however this blocks subsequent jobs from running it in parallel. In my opinion this is not possible to check status of other jobs without putting relation between them (in out of the box manner). Another approach (similar to one described by you) is REST API call to Azure DevOps to check job's status. But here your job will start and then you can fail it programitacally. – Krzysztof Madej Jul 12 '20 at 21:57
  • What do you mean not start any additional jobs? Do you mean cancel whole pipeline? You could [cancel pipeline through REST API](https://stackoverflow.com/questions/62044055/is-it-possible-to-cancel-a-azure-devops-pipeline-job-programmatically) Or you want the running jobs are still in progress and just want the queued jobs won't be run? I am afraid it is impossible. – starian chen-MSFT Jul 22 '20 at 13:10

1 Answers1

0

If you want to run jobs in parallel (no dependencies), it's not able to use a condition. If you want to check other jobs status, it will require starting the job. Maybe you can add a PowerShell task that cancel the pipeline when a task failed as this case mentioned:

steps:
- powershell: |
   Write-Host "Cancel all jobs..."
   $url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/builds/$($env:BUILD_BUILDID)?api-version=2.0"
    $header = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"  }
    $body = @{ 'status'='Cancelling' } | ConvertTo-Json
    Invoke-RestMethod -Uri $url -Method Patch -Body $body -Headers $header -ContentType application/json
  displayName: Cancel the pipeline
  condition: failed()
  env:
       System_AccessToken: $(System.AccessToken)
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • I do not wish to cancel any jobs (nor cancel the whole pipeline). I just don't want to start new jobs. – mernst Jul 13 '20 at 14:02
  • Unfortunately, your goal is not able to be achieved unless you use dependencies, but in this way, you are not able to run jobs in parallel. – Cece Dong - MSFT Jul 14 '20 at 01:37