PowerShell provisioner dies in the middle of the execution
- Dominant language
- Go
- Stars
- 15.8k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
#### Overview of the Issue
We noticed recently an issue where a provisioner (PowerShell script) gets canceled all of a sudden in the middle of the execution. Packer just continues with the next provisioner. The script contains error handling etc. There is no reason that the script "terminates" successful. Even log messages are missing in the output. It looks like, that the Packer provisioner processes just dies and Packer continues with the next.
Output of a successful run:
```log
1. Provisioning with Powershell...
2. Provisioning with powershell script: /azp/_work/1/s/images/win/scripts/Installers/Install-VS.ps1
3. Downloading Bootstrapper ...
4. Downloading package from: https://aka.ms/vs/16/release/vs_Enterprise.exe to path C:\Users\INSTAL~1\AppData\Local\Temp\vs_Enterprise.exe .
5. Package downloaded successfully in 0.36 seconds
6. Enable short name support on Windows needed for Xamarin Android AOT, defaults appear to have been changed in Azure VMs
7. Starting Install ...
8. Installation successful
9. 0
10. Restarting Machine
11. Waiting for machine to restart...
12. A system shutdown is in progress.(1115)
13. pkrvmz78ya8sie7 restarted.
14. Machine successfully restarted, moving on
```
Output of a failed run:
```log
1. Provisioning with Powershell...
2. Provisioning with powershell script: /azp/_work/1/s/images/win/scripts/Installers/Install-VS.ps1
3. Downloading Bootstrapper ...
4. Downloading package from: https://aka.ms/vs/16/release/vs_Enterprise.exe to path C:\Users\INSTAL~1\AppData\Local\Temp\vs_Enterprise.exe .
5. Package downloaded successfully in 0.36 seconds
6. Enable short name support on Windows needed for Xamarin Android AOT, defaults appear to have been changed in Azure VMs
7. Restarting Machine
8. Waiting for machine to restart...
9. A system shutdown is in progress.(1115)
10. pkrvmz78ya8sie7 restarted.
11. Machine successfully restarted, moving on
```
Notice, that the lines (7-9) are missing. Even if the installation fails, there should be more log messages. This [script](https://github.com/actions/virtual-environments/blob/1ce167f82d749f09c49fb8ae7a6ce4829b59ed1f/images/win/scripts/ImageHelpers/VisualStudioHelpers.ps1#L28-L68) gets executed.
Does anyone have or had similar issues, that the script execution just dies?
#### Reproduction Steps
\-
### Packer version
From `1.7.10`
### Simplified Packer Template
```json
{
"type": "powershell",
"valid_exit_codes": [
0,
3010
],
"scripts": [
"{{user `template_dir`}}/scripts/Installers/Install-VS.ps1"
],
"elevated_user": "{{user `install_user`}}",
"elevated_password": "{{user `install_password`}}"
},
{
"type": "windows-restart",
"restart_timeout": "10m"
}
```
### Operating system and Environment details
Packer runs in a Docker container. The base image is `ubuntu:20.04`.
### Log Fragments and crash.log files
\-
Contributor guide
Research direction
Start by reviewing the referenced VisualStudioHelpers.ps1 section and reproducing the simplified PowerShell provisioner template with Packer 1.7.10 in the ubuntu:20.04 container. Compare successful and failed output around installation and restart, and capture enough logs to determine why execution stops before the expected messages. Done means the provisioner no longer ends silently and Packer reports the correct outcome before continuing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100