Ever spent too much time debugging an issue that seemed impossible at first, but then turned out to be stupid? I have.

Pipeline

I was working on a pipeline. Just your run of the mill deployment pipeline really. I was trying to deploy some resources from a bicep template. It looked something like the following:

variables:
  path: $(Build.SourcesDirectory)/agw-bicep
  agwName: 'my-agw'
  agwRg: 'my-agw-rg'
  kvName: 'my-agw-kv'

trigger: none
pool:
  vmImage: ubuntu-latest

jobs:
- job: deploy
  pool:
    vmImage: ubuntu-latest
  timeoutInMinutes: 15
  steps:
  - task: AzureCLI@2
    displayName: 'Call Azure Cli'
    inputs:
      azureSubscription: '<sub>'
      scriptType: 'pscore'
      scriptLocation: 'inlineScript'
      workingDirectory: $(oath)
      inlineScript: |
      (...)      

Needless to say, it did not work. Can you spot the error?

It started me off with a hint: Azure-cli-broken

Azure Cli 2.x is not installed on this machine

Script failed with error: Error: Unable to locate executable file: 'pwsh'. Please verify either the file path exists (...)

So I figure, must be an issue with the agent that I was using. A couple runs later, after trying different agents, operating systems and container image runs I was no further.

So what else can I do to find out more? What if I go back to more simple stuff. What if it’s not the azure cli specifically? Let’s try a simple bash script.

variables:
  path: $(Build.SourcesDirectory)/agw-bicep
  agwName: 'my-agw'
  agwRg: 'my-agw-rg'
  kvName: 'my-agw-kv'

trigger: none
pool:
  vmImage: ubuntu-latest

jobs:
- job: deploy
  pool:
    vmImage: ubuntu-latest
  timeoutInMinutes: 15
  steps:
  - script: echo "Test"

bash-broken

Unable to locate executable file: 'bash'. Please verify either the file path exists of the file van be found within (...)

So it’s not the azure cli specifically. It’s the whole of bash. Or is it?

The Path variable

So in Azure DevOps Pipelines we’re allowed to create variables, as you can see in my examples.

variables:
  path: $(Build.SourcesDirectory)/agw-bicep
  agwName: 'my-agw'
  agwRg: 'my-agw-rg'
  kvName: 'my-agw-kv'

So as it turns out, these variables are also automatically set as environment variables on the agent. So what happens if you use a variable name that is coincidentally also a pretty fundamental system environment variable, like path? Exactly, no more simple commands.

As the output suggested, the runner could simply not locate any commands. Not az, not bash. Because the PATH variable was, unknown by me, overwritten with some arbitrary value that should not have been there.

Final note

Be careful with how you name your Azure DevOps variables, and be very aware of the consequences of overwriting system environment variables. Hope this saves you a couple of hours of staring at the same failing pipeline over and over.