Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REGRESSION]: Azure CLI@2 - toolExecutionError.indexOf is not a function #19726

Closed
4 of 7 tasks
ponbac opened this issue Apr 4, 2024 · 11 comments
Closed
4 of 7 tasks
Assignees
Labels
Area:RM RM task team bug regression This used to work, but a change in the service/tasks broke it. Task:AzureCLI Area:RM, Owners: @rvairavelu @manolerazvan

Comments

@ponbac
Copy link

ponbac commented Apr 4, 2024

New issue checklist

Task name

AzureCLI@2

Breaking task version

No response

Last working task version

No response

Regression Description

Our pipeline stopped working April 02 and the error message does not get logged since toolExecutionError.indexOf is not a function causes a crash.

This seems to have been introduced in this commit: 9e519cb by @LeftTwixWand.

The problem seems to be that you try to use indexOf on toolExecutionError which in some cases is neither a string nor an array at e.g. https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureCLIV2/azureclitask.ts#L101.

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

windows-2022

Relevant log output

==============================================================================
Task         : Azure CLI
Description  : Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.
Version      : 2.237.3
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli
==============================================================================
##[error]Unhandled: toolExecutionError.indexOf is not a function
##[error]TypeError: toolExecutionError.indexOf is not a function
    at azureclitask.<anonymous> (D:\a\_tasks\AzureCLI_46e4be58-730b-4389-8a2f-ea10b3e5e815\2.237.3\azureclitask.js:101:77)
    at Generator.next (<anonymous>)
    at fulfilled (D:\a\_tasks\AzureCLI_46e4be58-730b-4389-8a2f-ea10b3e5e815\2.237.3\azureclitask.js:5:58)


### Full task logs with system.debug enabled

_No response_

### Repro steps

```yml
schedules:
  - cron: "0 19 * * *"
    displayName: At 19:00 every day
    branches:
      include:
        - main
    always: true
pr: none
trigger: none
pool:
  vmImage: "windows-2022"

stages:
  - stage: abc
    jobs:
      - job: abc
        steps:
          - task: AzureCLI@2
            displayName: Take down qa appservices and serviceplan
            inputs:
              azureSubscription: "ABC"
              scriptType: ps
              scriptLocation: scriptPath
              scriptPath: "iac/azure-pipelines/abc.ps1"
@ponbac ponbac added bug regression This used to work, but a change in the service/tasks broke it. labels Apr 4, 2024
@JulianCodespotiMYOB
Copy link

I had a similar issue occur, but for me it was due to not passing in an appropriate Azure Subscription. Perhaps this could be your issue? Maybe try confirming whether this subscription exists or not 🤔

@ponbac
Copy link
Author

ponbac commented Apr 5, 2024

I had a similar issue occur, but for me it was due to not passing in an appropriate Azure Subscription. Perhaps this could be your issue? Maybe try confirming whether this subscription exists or not 🤔

Yes, the reason our pipeline is failing in the first place is due to something else, but this issue is about the error not getting properly logged because of the indexOf error crashing the task before the real error can get reported.

@jonmikeli
Copy link

Some issue for me with a service connection.

@LeftTwixWand
Copy link
Contributor

LeftTwixWand commented Apr 5, 2024

Hello @ponbac, @JulianCodespotiMYOB and @jonmikeli
Thank you for reaching me.

As @ponbac noticed, my changes do not work properly. But the indexOf issue occurs in the error-handling part of the code.
Which means that the error has already happened.

The most common reason for service connection error - is expired secrets.
So please, check the secrets on your service connection are valid.
If not - please update the secrets or (recommended): convert your service connection from secrets-based to Workload Identity Federation. This should mitigate the issue for some of you.

From my side, I'll try to revert the changes asap.

@LeftTwixWand LeftTwixWand self-assigned this Apr 5, 2024
@shanoor
Copy link

shanoor commented Apr 5, 2024

Meanwhile, we can use the previous version of the task by using task: AzureCLI@2.236.0.

@ghost
Copy link

ghost commented Apr 5, 2024

Adding a note that I am using service connections with federated identity and recevied the same error. Using @shanoor's comment about downgrading the task version bypassed the error.

@chandlerkent
Copy link
Contributor

Just wanted to note that we are also having this issue and we are also using Workload Identity Federation. Downgrading as suggested by @shanoor fixes the issue.

@LeftTwixWand

@jonmikeli
Copy link

Hello @ponbac, @JulianCodespotiMYOB and @jonmikeli Thank you for reaching me.

As @ponbac noticed, my changes do not work properly. But the indexOf issue occurs in the error-handling part of the code. Which means that the error has already happened.

The most common reason for service connection error - is expired secrets. So please, check the secrets on your service connection are valid. If not - please update the secrets or (recommended): convert your service connection from secrets-based to Workload Identity Federation. This should mitigate the issue for some of you.

From my side, I'll try to revert the changes asap.

Hi @LeftTwixWand ,

Thank you for your answer.
In case it helps, I have created a new connection and same result.

I will use the former version while the issue is solved.

@v-mohithgc v-mohithgc added Area:RM RM task team Task:AzureCLI Area:RM, Owners: @rvairavelu @manolerazvan and removed Area: Release triage labels Apr 8, 2024
@LeftTwixWand LeftTwixWand mentioned this issue Apr 9, 2024
2 tasks
@laplace-deploy
Copy link

Same problem here, even using Workload Identity Federation

@iurietopor
Copy link

iurietopor commented Apr 12, 2024

Faced the issue today. We are using Workload Identity Federation as well.

Edit:
Found the issue on our side. azureSubscription: '' under task inputs:.
We didn't apply the template with variables for new added job. The name of service connection is defined there.

Used this Google Chrome extension to see the final rendered YAML: ADO Pipeline Assistant

Relevant snippet from final rendered YAML:

    - task: AzureCLI@2
      displayName: Get WebApp Host-Name
      inputs:
        azureSubscription: ''
        scriptType: bash
        ....

@ajayadav7
Copy link

if you use task: AzureCLI@2.236.0 then you will get the error: 'unable to locate executable file: 'powershell'. Please verify.....

and this is the actual error.

to resolve this just add the pool image as 'windows-latest' and it will work with task: AzureCLI@2 also.

you need to add the below part in your script before the task

pool:
vmImage: "windows-latest"
steps:

  • task: AzureCLI@2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:RM RM task team bug regression This used to work, but a change in the service/tasks broke it. Task:AzureCLI Area:RM, Owners: @rvairavelu @manolerazvan
Projects
None yet
Development

No branches or pull requests

10 participants