Fix for Azure DevOps deployment to an environment stuck in "Job is pending" state

Issue

I had an Azure DevOps YAML based pipeline that had been working but was now getting stuck with the message "Job is pending..." when trying to start a stage in which there is a deployment to an environment.

Looking at the logs and Azure DevOps UI it was not obvious what the issue was.

Solution

Turns out it was due to environment checks and approvals. There was a branch policy on the environment. This was set to only allow use of Azure DevOps Templates on a given branch. The edit that had been done to the YAML meant it was trying to extend a template in a branch that was not in the approved list.

As soon as the working branch was added to the proved list it all worked as expected.

So if you see "Job is pending" errors with no obvious reason, check the environment approvals and checks. Remember, any issues with these don't show up in the build log