0

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
4
  • 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? Commented Sep 9, 2020 at 8:45
  • By the way, please also try run this build via hosted agent and then kindly share the result here. Thanks. Commented Sep 9, 2020 at 9:39
  • @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. Commented Sep 9, 2020 at 12:20
  • 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? Commented Sep 10, 2020 at 2:56

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Upgrading to DevOps 2020 RC2 fixed the problem.
0

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'

4 Comments

Thank you for the suggestions, I did validate the service connection and the YAML file itself. I've updated the question to show that v1 works. I don't need to use v2 necessarily, so maybe it's fine as is for me.
So it looks that there is an issue with v2 on self hosted agent. Or maybe you are missing some settings on your agent. Since v1 works for you you have your solution. Maybe not the best, but at least working. Maybe this is worth of creating issue on Github?
I edited my answer including details from our conversation to take off this topic from the radar of other SO users. If you are fine to accept it as answer and upvote I will appreciate. You can also create your own answer of course. But it would be good to mark this topic as solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.