How to update an Azure DevOps pipeline file to specify a timeout value
Learn how to add logic into the pipeline file to avoid a default timeout on self-host Azure DevOps agent.
Recently, when using a self hosted agent in Azure DevOps, the build I was running kept timing out because it was running for longer than 60 minutes.
When reading the Microsoft documentation as of February 2020, it looks like any build on a self-hosted agent should run forever, but this is not the case.
I received this error on my self-hosted agent when running a build that took longer than 60 minutes.
To fix this, the YAML needs to get updated to specify a timeout greater than 60
or 0
which would be infinite. Here is how I added the timeout values into my YAML file. See the jobs
section.
trigger:
branches:
include:
- '*'
paths:
exclude:
- README.md
- CHANGELOG.md
name: $(BuildID)
variables:
- group: key-vault-values
jobs:
- job: my_job
timeoutInMinutes: 120
cancelTimeoutInMinutes: 3
pool: 'my-self-hosted-pool'
steps:
- checkout: self
- task: PowerShell@2
inputs:
targetType: 'filePath'
filePath: "$(System.DefaultWorkingDirectory)/my-script.ps1"
arguments: "-SubscriptionId $(azure_subscription)"
env:
ClientID: $(ClientID)
ClientSecret: $(Client_Secret)
TenantId: $(TenantId)
displayName: 'Run Script'
I left the rest of the YAML to give more context as to where to add the jobs
section and how to indent the rest of the code underneath it properly. I couldn’t find many examples online, I hope this helps!