jenkins-infra / packer-images

This repository hosts the packer definitions for the Jenkins Infrastructure
MIT License
18 stars 18 forks source link

bug(Windows all) error when calling `pwsh` #409

Closed dduportal closed 1 year ago

dduportal commented 1 year ago

Today, a new set of errors appeared on all the Windows Server images we are building. It blocks the build on the main branch (as well as on PRs).

The error is the following:

[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows: Invoke-Command : The term 'C:\Program Files\PowerShell\7\pwsh.exe' is not recognized as the name of a cmdlet,
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows: function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows: path is correct and try again.
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows: At C:\Windows\Temp\script-636b7724-abe6-c98a-267b-840c00817f86.ps1:381 char:1
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows: + Invoke-Command {& "C:\Program Files\PowerShell\7\pwsh.exe" -command " ...
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows:     + CategoryInfo          : ObjectNotFound: (C:\Program Files\PowerShell\7\pwsh.exe:String) [Invoke-Command], Comman
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows:    dNotFoundException
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows:     + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.InvokeCommandCommand
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z:     amazon-ebs.windows:
[2022-11-09T10:14:20.074Z] 2022-11-09T10:14:19Z: ==> amazon-ebs.windows: Provisioning step had errors: Running the cleanup provisioner, if present...

The Windows porivisoning scripts resolves the path to pwsh with an absolute directory (https://github.com/jenkins-infra/packer-images/blob/54fe4ace0bc61c7bc3468bed7dea6e1efed6f0e3/provisioning/windows-provision.ps1#L373) which could be the cause.

dduportal commented 1 year ago

Digging a bit more:

[2022-11-09T09:35:57.854Z] 2022-11-09T09:35:57Z:     azure-arm.windows: == Ensure both Windows Powershell and Powershell Core are available
[2022-11-09T09:35:57.854Z] 2022-11-09T09:35:57Z:     azure-arm.windows: = Windows Powershell already present, installing Powershell Core...
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows: Installing the following packages:
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows: pwsh
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows: By installing, you accept licenses for the packages.
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows: pwsh not installed. An error occurred during installation:
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows:  Unable to resolve dependency 'powershell-core (= 7.3.0)'.
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows: pwsh package files install failed with exit code 1. Performing other installation steps.
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows: The install of pwsh was NOT successful.
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows: pwsh not installed. An error occurred during installation:
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows:  Unable to resolve dependency 'powershell-core (= 7.3.0)'.
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows:
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows: Chocolatey installed 0/1 packages. 1 packages failed.
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows:  See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows:
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows: Failures
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows:  - pwsh (exited 1) - pwsh not installed. An error occurred during installation:
[2022-11-09T09:35:59.728Z] 2022-11-09T09:35:59Z:     azure-arm.windows:  Unable to resolve dependency 'powershell-core (= 7.3.0)'.
dduportal commented 1 year ago

Gosh, sounds like a recurring issue: pwsh is a virtual package pointing to powershell-core. But both are not update synchronously each time: https://community.chocolatey.org/packages/powershell-core (currently only 7.3.0-rc1 is available for powershell-core while pwsh was updated to7.3.0` yesterday).

dduportal commented 1 year ago

=> Gotta fix the version and add an updatecli manifest that will check for BOTH packages available before opening a PR.