Azure / powershell

GH Action to run Az PowerShell scripts for developers and administrators to develop, deploy, and manage Microsoft Azure applications.
MIT License
60 stars 40 forks source link

Specifying latest for the azPSVersion generates an exception on the Ubuntu hosted agent #43

Closed wlhutchison closed 3 years ago

wlhutchison commented 3 years ago

On the Ubuntu runner, the following yaml snipped will generate an exception (burying the output) :

    steps:
    - name: checkout
      uses: actions/checkout@v2
    - name: 'Azure PowerShell script: Inline Script Version'
      continue-on-error: true
      uses: Azure/login@v1
      with:
        creds: "${{ secrets.AZURE_CREDENTIALS }}"
    - name: 'Azure PowerShell script: Inline Script Version'
      continue-on-error: true
      uses: azure/powershell@v1
      with:
        inlineScript: |-
          Write-Host "Testing 1.2..3..."
          Get-ChildItem
        errorActionPreference: Stop
        failOnStandardError: false
        azPSVersion: "latest"

The exception output is:

Run azure/powershell@v1
Validating inputs
Module Az latest installed from hostedAgentFolder
Initializing Az Module
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command Test-Path (Join-Path /usr/share az_*)
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command try ***
            $ErrorActionPreference = "Stop"
            $WarningPreference = "SilentlyContinue"
            $output = @***
            $data = Get-Module -Name Az -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
            $output['AzVersion'] = $data.Version.ToString()
            $output['Success'] = "true"
        ***
        catch ***
            $output['Error'] = $_.exception.Message
        ***
        return ConvertTo-Json $output
Process terminated. The type initializer for 'Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry' threw an exception.
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry' threw an exception.
 ---> System.IO.IOException: The system cannot open the device or file specified. : 'CreateUniqueUserId'
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
   at Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry.GetUniqueIdentifier() in /PowerShell/src/System.Management.Automation/utils/Telemetry.cs:line 802
   at Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry..cctor() in /PowerShell/src/System.Management.Automation/utils/Telemetry.cs:line 548
   --- End of inner exception stack trace ---
   at Microsoft.PowerShell.Telemetry.ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry(String mode) in /PowerShell/src/System.Management.Automation/utils/Telemetry.cs:line 656
   at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs:line 248
(node:1671) UnhandledPromiseRejectionWarning: Error: The process '/usr/bin/pwsh' failed with exit code null
    at ExecState._setResult (/home/runner/work/_actions/azure/powershell/v1/node_modules/@actions/exec/lib/toolrunner.js:561:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/azure/powershell/v1/node_modules/@actions/exec/lib/toolrunner.js:544:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/azure/powershell/v1/node_modules/@actions/exec/lib/toolrunner.js:444:27)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
(node:1671) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1671) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs:line 99***
  "AzVersion": "6.1.0",
  "Success": "true"
***
Initializing Az Module Complete
Running Az PowerShell Script
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command /home/runner/work/_temp/f6af17b0-6b1e-4ebb-b04d-5a5cadbd0600.ps1
Testing 1.2..3...

    Directory: /home/runner/work/valet-testing/valet-testing

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-----          09/03/2021    01:07             37 README.md

This happens when azPSVersion is latest, 'latest', or "latest".

However it works if a specific azPSVersion is specified such as: 3.1.0 or 6.1.0.

That is, the following action.yml generates the appropriate output:

    steps:
    - name: checkout
      uses: actions/checkout@v2
    - name: 'Azure PowerShell script: Inline Script Version'
      continue-on-error: true
      uses: Azure/login@v1
      with:
        creds: "${{ secrets.AZURE_CREDENTIALS }}"
    - name: 'Azure PowerShell script: Inline Script Version'
      continue-on-error: true
      uses: azure/powershell@v1
      with:
        inlineScript: |-
          Write-Host "Testing 1.2..3..."
          Get-ChildItem
        errorActionPreference: Stop
        failOnStandardError: false
        azPSVersion: 6.1.0

In this case, the run succeeds without an exception:

Run azure/powershell@v1
Validating inputs
Module Az 6.1.0 installed from hostedAgentFolder
Initializing Az Module
Initializing Az Module Complete
Running Az PowerShell Script
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command Test-Path (Join-Path /usr/share az_*)
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command /home/runner/work/_temp/84acae14-92ca-479b-8ac8-08753b234257.ps1
Testing 1.2..3...
True

    Directory: /home/runner/work/valet-testing/valet-testing

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-----          09/03/2021    01:29             37 README.md

Script execution Complete

On a Windows runner, the azPSVersion works with either the latest or a numeric specification.

BALAGA-GAYATRI commented 3 years ago

Hey @wlhutchison, if you want to use powershell action for running any Az-ps script you need to set enable-AzPSSession: true. So the login action part which is a prerequisite should look like

- name: 'Az CLI login'
   uses: azure/login@v1
   with:
       creds: ${{ secrets.AZURE_CREDENTIALS }}
       enable-AzPSSession: true

This will definitely accept your azPSVersion: "latest" in the workflow.

BALAGA-GAYATRI commented 3 years ago

closing this issue. Feel free to reopen this if the issue persists.