actions / runner-images

GitHub Actions runner images
MIT License
10.15k stars 3.06k forks source link

Error with StartProcess and az command #6239

Closed damienmartel2 closed 2 years ago

damienmartel2 commented 2 years ago

Description

In a powershell task i am using the code :

    if ($ok) {
        $arg = "artifacts universal publish --organization `"$OrganizationUrl`" --project `"$Project`" --scope project --feed `"$Feed`" --name `"$Name`" --version `"$Version`" --description `"$Description`" --path `"$ArtifactPath`" "
        $process = Start-Process -NoNewWindow -FilePath "az" -ArgumentList $arg -Wait -PassThru 
        if ($process.ExitCode -ne 0) {
            $ok = $false   
            $errorMessage = "Error $($process.ExitCode) occurred executing az `"$ArtifactPath`""
            Trace-Report -Message $errorMessage -Color Red
            Throw $errorMessage 
        }
    }

Without changes the pipeline now fails with this error

Start-Process : This command cannot be run due to the error: %1 is not a valid Win32 application.
At C:\Program Files\WindowsPowerShell\Modules\MSBuildTools\0.1.3\MSBuildTools.psm1:527 char:20
+ ...  $process = Start-Process -NoNewWindow -FilePath "az" -ArgumentList $ ...

It seems to have an issue with the command az...

Platforms affected

Runner images affected

Image version and build link

20220911.1

Is it regression?

yes it worked with 20220905.1

Expected behavior

The command is ok or an error message or an alternative

Actual behavior

The command fails

Repro steps

you will have the error

al-cheb commented 2 years ago

Hey @damienmartel2.

az is a powershell script now:

PS > Get-Content (Get-Command az).Source
$env:AZ_INSTALLER="MSI"
& "$PSScriptRoot\..\python.exe" -IBm azure.cli $args

image

az account list - should work

damienmartel2 commented 2 years ago

Ok the problem is Azure Cli has been updated and so now there is an az.ps1 so i need to make "az.cmd" in order to continue to call the good program...

damienmartel2 commented 2 years ago

sorry @al-cheb i didn't show your answer. It's exactly that ;) thanks