0
votes

I'm getting the following error while trying to use the Azure CLI task in my DevOps YAML pipeline:

"An error occurred while loading the YAML build pipeline. wrong number of segments"

I'm following this documentation, running on a self-hosted Windows agent with Azure CLI and PowerShell Core installed.

  - task: AzureCLI@2
    displayName: Azure CLI
    inputs:
      azureSubscription: MyServiceName
      scriptType: pscore
      scriptLocation: inlineScript
      inlineScript: az --version

UPDATED: There are no other tasks in the file and it is valid. As an experiment I changed the task to AzureCLI@1 and it worked (v1 does not include Script Type):

- task: AzureCLI@1
  displayName: Azure CLI
  inputs:
    azureSubscription: MyServiceName
    scriptLocation: inlineScript
    inlineScript: az --version
2
Hi @michaelrp, If a task is referenced by a wrong version number, I can get the error message, please check the yaml definition and ensure that other task version is correct. If you still have this issue, could you please share the full YAML build definition here?Vito Liu
By the way, please also try run this build via hosted agent and then kindly share the result here. Thanks.Vito Liu
@VitoLiu-MSFT, thank you for the response. I did switch it to v1 and that worked in our setup. There is really nothing else in the YAML, just this one task. Unfortunately, we are not able to use hosted agents for this project.michaelrp
Hi @michaelrp, Thank you for your confirmation. I have added a answer, if the answer could give you some help, you can feel free to accept it or you can feel free to raise your owner answer and accept it, others could directly find the useful solution. By the way, This issue should be related to the self-hosted agent. Is this self-hosted agent deployed on the window, macOS or Linux?Vito Liu

2 Answers

0
votes

As michaelrp found the issue was version 2 of AzureCLI task. When he downgraded to version 1, the error goes away. It appers only on self hosted agent.

This is caused by some issue with your YAML file. Please validate your YAML file and make sure it passes

enter image description here

It can be caused also by wrong number of task which is fine here AzureCLI@2.

It could be also an issue with service connection, please make sure you use valid.

To give you an better answer I need to see your full YAML file.

I tested this and all went fine:


trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: AzureCLI@2
  inputs:
    azureSubscription: 'rg-the-code-manual'
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    inlineScript: 'az --version'
0
votes

If a task is referenced by a wrong version number, we could get the error message: An error occurred while loading the YAML build pipeline. wrong number of segments

As a workaround, downgraded the task AzureCLI to version 1, then the task will run successfully.

Note: michaelrp has raised this issue in the GitHub, please follow this ticket to get the latest news.