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

AzurePowerShellV5 task cannot find bicep from path, bicep related commands are failing #14934

Closed
jikuja opened this issue Jun 6, 2021 · 11 comments
Assignees
Labels
Area: Release bug environment:need-to-triage Issues need to be triage by environment-deployment team Task: AzurePowerShell

Comments

@jikuja
Copy link

jikuja commented Jun 6, 2021

Required Information

Type: Bug

Enter Task Name: AzurePowerShellV5

Environment

  • Server - Azure Pipelines
  • Agent - Hosted

Issue Description

The task does not find bicep command from path

Task logs

2021-06-06T13:46:30.3275217Z ##[section]Starting: What-if
2021-06-06T13:46:30.3394875Z ==============================================================================
2021-06-06T13:46:30.3395191Z Task         : Azure PowerShell
2021-06-06T13:46:30.3395424Z Description  : Run a PowerShell script within an Azure environment
2021-06-06T13:46:30.3395878Z Version      : 5.185.0
2021-06-06T13:46:30.3396076Z Author       : Microsoft Corporation
2021-06-06T13:46:30.3397079Z Help         : https://aka.ms/azurepowershelltroubleshooting
2021-06-06T13:46:30.3397473Z ==============================================================================
2021-06-06T13:46:31.3726602Z Generating script.
2021-06-06T13:46:31.4170471Z ========================== Starting Command Output ===========================
2021-06-06T13:46:31.4354473Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\4ca7a1bd-1b8d-4f5f-8727-4da088435f92.ps1'"
2021-06-06T13:46:33.8309539Z ##[command]Import-Module -Name C:\Modules\az_5.7.0\Az.Accounts\2.3.0\Az.Accounts.psd1 -Global
2021-06-06T13:46:41.1353500Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2021-06-06T13:46:42.0562735Z ##[command]Clear-AzContext -Scope Process
2021-06-06T13:46:42.5257904Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2021-06-06T13:46:44.3150111Z ##[command] Set-AzContext -SubscriptionId 8a4fb900-f5b3-4645-a52b-7faf38f07f51 -TenantId ***
2021-06-06T13:46:48.3798080Z ##[error]Cannot retrieve the dynamic parameters for the cmdlet. Cannot find Bicep. Please add Bicep to your PATH or visit https://github.com/Azure/bicep/blob/main/docs/installing.md to install Bicep.
2021-06-06T13:46:48.5037095Z ##[error]PowerShell exited with code '1'.
2021-06-06T13:46:49.0313204Z ##[section]Finishing: What-if

when running following task

          - task: AzurePowerShell@5
            displayName: What-if
            continueOnError: true
            inputs:
              azureSubscription: $(serviceConnection)
              ScriptType: 'inlineScript'
              inline: |
                $DeploymentParameters = [ordered]@{
                  ResourceGroupName = "$(resourceGroupName)"
                  TemplateFile = "$(Build.SourcesDirectory)\main.yml"
                }
                New-AzResourceGroupDeployment @DeploymentParameters -project "${{ parameters.project }}" -environment "${{ parameters.environment }}" -WhatIf -WhatIfResultFormat FullResourcePayloads
              azurePowerShellVersion: LatestVersion
@github-actions github-actions bot added Area: Release bug environment:need-to-triage Issues need to be triage by environment-deployment team Task: AzurePowerShell labels Jun 6, 2021
@brwilkinson
Copy link

brwilkinson commented Jun 8, 2021

One more comment on this one...

I believe the current AZ.Resources version on this AzurePowerShell@5 task is: 3.4.0 [which comes in AZ module 5.7.0]

image

find-module az.resources -allversions

4.1.0      works (major)
3.5.0      works (minor)
3.4.1      fixed (patch)
3.4.0      fails on warning   <-- current default version for this task

That particular version has a known issue with failing on warnings for new-azresourcegroupdeployment. That has been fixed on newer versions. This causes issues with bicep 0.4.x based on the Linting rules.

So applying the 3.4.1 patch release of az.resources would be the easiest way to resolve the issue...

So this would be part of the AZ module update. . updating the task to AZ 5.8.0, 5.9.0 or 6.0.0.

find-module az -allversions |  where version -ge 5.7.0 |
 select name,version,@{n='az.resources';e={$_.Dependencies |  where name -eq 'az.resources' |  foreach requiredversion}}

Name Version az.resources
---- ------- ------------
Az   6.0.0   4.1.0
Az   5.9.0   3.5.0
Az   5.8.0   3.4.1
Az   5.7.0   3.4.0

Also for @jikuja in the meantime to get past the issue, you can manually install bicep with the az cli at the moment, it's coming to azure powershell soon.

Something like below in your pipeline should be the workaround.

if (-not (gcm bicep -ea 0))
{
    az bicep install
}

if you do manually install it you will also have to manually update the AZ modules.. to avoid what I mentioned above.

via the following, on your task. or you could install any version listed above greater than the default 3.4.0.

        # azurePowerShellVersion: 'LatestVersion'
        preferredAzurePowerShellVersion: 6.0.0

@chshrikh
Copy link
Contributor

chshrikh commented Jun 9, 2021

please share the debug logs

@brwilkinson
Copy link

brwilkinson commented Jun 9, 2021

Debug logs? Bicep.exe is an external tool used for deploying ARM templates to Azure.

https://github.com/azure/bicep

Are you able to update to the newer AZ module for this task 5.8.0 or 5.9.0?

@chshrikh
Copy link
Contributor

chshrikh commented Jun 9, 2021

@brwilkinson if you can share the "Azure PowerShell" task's debug logs from pipeline, we will able to identify the source of error.

@brwilkinson
Copy link

brwilkinson commented Jun 9, 2021

I have outlined that above.

The source of the error is a known issue in AZ.resources 3.4.0.

Also Bicep is new. Also info above on installing it with the AZ cli.

I believe this one..

PR/fix: Azure/azure-powershell#14449

Issue:
Azure/azure-powershell#14508

@brwilkinson
Copy link

What is the criteria to move to AzurePowerShell@6?

Is it a breaking change I.E. Major version change of the AZ modules?

Is it possible to just bump the minor Version of AZ modules and stay with AzurePowerShell@5?

@AmrutaKawade
Copy link
Contributor

There are three ways to update Az modules version.

  1. In the task instead of latest version use preferred version
  2. On private agent install required Az modules and then use latest
  3. For hosted agent add issue here https://github.com/actions/virtual-environments/issues to update

@brwilkinson
Copy link

@jikuja I opened this issue to track your Bicep query.

actions/runner-images#3558

I believe it should be okay to close this issue now ?

@AmrutaKawade
Copy link
Contributor

yes. we will close this issue

@jikuja
Copy link
Author

jikuja commented Jun 11, 2021

This should be re-opened and wait to see if bicep binary is added for hosted agents images or not. The current workarounds given in the virtual-environments ticket are kind of unfeasible:

  1. Run a task to install binary. Do I really need to use third-party tasks for using all AZ.Resources features?
  2. Run curl without any caching to download and install 40MB binary without any caching.

Maybe AZ.Resources should bundle bicep like AZ CLI does?

@brwilkinson
Copy link

brwilkinson commented Jun 11, 2021

@jikuja I somewhat agree, however this is not the only task that would require Bicep.

As an example the "AzureResourceGroupDeploymentV2" and "AzureCLIV2" task would also need it.

Then there are GitHub workflows and DevOps pipelines to consider.

So this may not be the best place, ... there should be a solution that is easy to manage... We can see if we can figure that out.

In the meantime this single line installs it: az bicep install

or with error handling

if (-not (gcm bicep -ea 0))
{
    az bicep install
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Release bug environment:need-to-triage Issues need to be triage by environment-deployment team Task: AzurePowerShell
Projects
None yet
Development

No branches or pull requests

5 participants