arcus-azure / arcus.scripting

Scripting with Microsoft Azure in a breeze.
https://scripting.arcus-azure.net/
MIT License
9 stars 11 forks source link

Devops pipeline powershell failing after Import Arcus.Scripting.LogicApps #389

Open bramvanhautte opened 1 year ago

bramvanhautte commented 1 year ago

Describe the bug Since 23/05/2023 I am facing issues after importing the Arcus.Scripting.LogicApps powershell module. From the moment I import the module, no Powershell task is still working.

I am using a Hosted agent running on windows-latest and using the powershell@5 task in my YAML file.

To Reproduce Steps to reproduce the behavior: Take a DevOps Hosted agent running on windows-latest, use a powershell task to Import Arcus.Scripting.LogicApps and after that try to run a Powershell@5 task.

Expected behavior Being able to run powershell scripts after Arcus.Scripting.LogicApps import

Additional context Let me show you what happens and what I have spotted being an issue. I know that I have AzureRM and Az warnings but I am currently only using Az in this pipeline.

1) First off, I run a Powershell@5 task which outputs the value '1' for testing purposes. This works fine. Note that the Import-Module for Az.Accounts is automatically called and using folder path 2.12.2:

- task: AzurePowerShell@5 displayName: 'Powershell task before arcus import' inputs: azureSubscription: ${{ parameters.AzureSubscription }} ScriptType: 'InlineScript' Inline: 'Write-Output 1' azurePowerShellVersion: 'LatestVersion' pwsh: true enabled: true

image

2) Then, I import the Arcus.Scripting.LogicApps module, which is successful:

- pwsh: Install-Module -Name Arcus.Scripting.LogicApps -Scope CurrentUser -Force displayName: 'Installing Arcus.Scripting.LogicApps Powershell module' enabled: true

image

3) After this, I try to run a Powershell@5 again but without success. Note how it now tries to import the Az.Accounts module from another path: 2.12.3:

- task: AzurePowerShell@5 displayName: 'Powershell task after arcus import' inputs: azureSubscription: ${{ parameters.AzureSubscription }} ScriptType: 'InlineScript' Inline: 'Write-Output 1' azurePowerShellVersion: 'LatestVersion' pwsh: true enabled: true

image

After the Arcus.Scripting.LogicApps import the Powershell@5 task tries to load a different Az.Account version which then conflicts with the current version it looks like.

fgheysels commented 1 year ago

Hi,

What happens if you install the Arcus powershell module like this:

PS> Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
PS> Install-Module -Name Arcus.Scripting.LogicApps -AllowClobber

as described in the docs ?

If the above doesn't bring a soltution, you can install the previous version of Arcus.Scripting as a temporary workaround,in your pipeline. (If you don't specify a version number, the latest version will be installed.

Install-Module Arcus.Scripting.LogicApps -MaximumVersion v0.8.0

oth, latest version of Arcus.Scripting has been released 2 weeks ago. How often do you run the pipeline ? Have you run your pipeline in the past 2 weeks without issues ?

pim-simons commented 1 year ago

I can indeed replicate the issue when using Install-Module -Name Arcus.Scripting.LogicApps -Scope CurrentUser -Force.

The suggestion from @fgheysels solves the error (at least in my test 😉), if you use this to install the module then the pipeline should work correctly:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name Arcus.Scripting.LogicApps -AllowClobber

@bramvanhautte can you validate if this indeed works for you?

bramvanhautte commented 1 year ago

Hi @fgheysels @pim-simons, thanks for the fast replies.

When using the below I did get it to work but only when using the AzurePowershell@5 YAML step to Install them.

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name Arcus.Scripting.LogicApps -AllowClobber

When I use normal powershell YAML to install the modules, and then switch to AzurePowerShell@5 for another task, it fails with the same error. When I use normal powershell YAML to install the modules, and then use the same normal powershell to do a dummy 'Write-Output' it still works. But my guess is that this is because normal powershell YAML does not load up Az.Accounts before executing any commands given by the user.

For the question when this started happening: the pipeline worked fine on 22/05 and stopped working on 23/05. I will be using only AzurePowershell@5 in my specific situation, but it still looks odd to me it suddenly stopped working but since Arcus had an update 2 weeks ago already I think it might not an issue invoked by Arcus.

Thank you!

fgheysels commented 1 year ago

Can you re-produce the issue when you install the previous version of Arcus.Scripting instead ?

bramvanhautte commented 1 year ago

When installing the version 0.8.0 it's giving me the same issues:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted Install-Module Arcus.Scripting.LogicApps -MaximumVersion 0.8.0 -AllowClobber

And after that, when using AzurePowershell@5 I get that same error: image

From the moment I install Arcus.Scripting.{module} and I then use any AzurePowershell@5 task it wants to install the Az.Accounts module at the 2.12.3 folder path for some reason but we already have a version installed at the 2.12.2 path.

Does Arcus install automatically installs/loads Az.Accounts?

pim-simons commented 1 year ago

I searched through the entire codebase, the only reference I can find to Az.Accounts is in one of the test files here.

fgheysels commented 1 year ago

Can we reproduce this on other devops agents (linux for instance, or what if we do not use windows-latest but specify an actual version-nr instead )?

bramvanhautte commented 1 year ago

I will do some testing on the above. Update following soon.

stijnmoreels commented 10 months ago

@bramvanhautte , any update on this?