Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bolt --target localhost munges puppet's non-zero exit codes #1846

Closed
sheenaajay opened this issue May 26, 2020 · 2 comments · Fixed by #1887
Closed

bolt --target localhost munges puppet's non-zero exit codes #1846

sheenaajay opened this issue May 26, 2020 · 2 comments · Fixed by #1887
Assignees
Labels
Bug Bug reports and fixes.

Comments

@sheenaajay
Copy link

sheenaajay commented May 26, 2020

Describe the Bug

bolt command run --targets localhost 'puppet ...' does not correctly report exit codes that are not 0 or 1:

2020-05-27_11MS+0100_1140x327

Expected Behavior

Notably the command in the screenshot above is returning exit code 2 and bolt should have correctly reported this.

Steps to Reproduce

  • get a win-2012r2-x86_64 machine from vmpooler
  • Install latest bolt package 2.10.0
  • Execute the following command:
bolt command run --targets localhost 'puppet apply --trace --detailed-exitcodes "notify { foo: }"'

and it throws the following error

2020-05-27_12MS+0100_1237x390

Note how bolt reports exitcode 1, but the same command executed through the powershell has the expected $LASTEXITCODE of 2 ("something changed").

Environment

  • Appveyor (win32) and its failing only on win32
  • Platform [windows]
  • bolt version 2.10.0

Additional Context

In our testing we could not reproduce the behaviour with bolt 2.6.0. This is currently impacting our testing and we're rolling temporarily back to that version to unblock our pipelines.

Please let us know if you need more information. Thanks a lot for all the help.

@sheenaajay sheenaajay added the Bug Bug reports and fixes. label May 26, 2020
@sheenaajay sheenaajay reopened this May 26, 2020
@sheenaajay sheenaajay changed the title bolt gem throws error on apply_manifest(pp, expect_changes: true) / (catch_failures: true) for win32 bolt gem throws error different error code for run a command for win32 May 26, 2020
@DavidS DavidS changed the title bolt gem throws error different error code for run a command for win32 bolt --target localhost munges non-zero exit codes May 27, 2020
@DavidS DavidS changed the title bolt --target localhost munges non-zero exit codes bolt --target localhost munges puppet's non-zero exit codes May 27, 2020
@DavidS
Copy link
Contributor

DavidS commented May 27, 2020

Updated initial description with easier repro without extra module and additional screenshots.

@lucywyman lucywyman assigned lucywyman and unassigned lucywyman Jun 1, 2020
@lucywyman lucywyman reopened this Jun 8, 2020
@lucywyman
Copy link
Contributor

Sorry fatfinger 😅

lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 9, 2020
Powershell will [exit
1](PowerShell/PowerShell#11461) whenever the $LASTEXITCODE is greater
than 0, regardless of what the code is, whenever running a bare command.
Powershell exits with the correct exit code when executing files, or
when `exit $LASTEXITCODE` is appended to the command being run (as in
the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands through Bolt, and
not tasks or scripts.  This modifies powershell's `run_command` function
to always wrap the command in a file and execute the file, which will
consistently return the correct exit code without attempting to modify
the command itself.

Closes puppetlabs#1846

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 9, 2020
Powershell will [exit
1](PowerShell/PowerShell#11461) whenever the $LASTEXITCODE is greater
than 0, regardless of what the code is, whenever running a bare command.
Powershell exits with the correct exit code when executing files, or
when `exit $LASTEXITCODE` is appended to the command being run (as in
the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands through Bolt, and
not tasks or scripts.  This modifies powershell's `run_command` function
to always wrap the command in a file and execute the file, which will
consistently return the correct exit code without attempting to modify
the command itself.

Closes puppetlabs#1846

!bug

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 9, 2020
Powershell will [exit
1](PowerShell/PowerShell#11461) whenever the $LASTEXITCODE is greater
than 0, regardless of what the code is, whenever running a bare command.
Powershell exits with the correct exit code when executing files, or
when `exit $LASTEXITCODE` is appended to the command being run (as in
the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands through Bolt, and
not tasks or scripts. This modifies powershell's `run_command` to
append 'exit $LASTEXITCODE', which will correctly exit the powershell
command with the exit code of the command it ran.

Closes puppetlabs#1846

!bug

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 9, 2020
Powershell will [exit 1](PowerShell/PowerShell#11461) whenever the
$LASTEXITCODE is greater than 0, regardless of what the code is,
whenever running a bare command. Powershell exits with the correct exit
code when executing files, or when `exit $LASTEXITCODE` is appended to
the command being run (as in the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands using the local
transport through Bolt. This modifies the local transport to append `;
exit $LASTEXITCODE` to commands run on Windows, which will correctly
return the exit code from the command run instead of changing it to 1.

Closes puppetlabs#1846

!bug

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 9, 2020
Powershell will [exit 1](PowerShell/PowerShell#11461) whenever the
$LASTEXITCODE is greater than 0, regardless of what the code is,
whenever running a bare command. Powershell exits with the correct exit
code when executing files, or when `exit $LASTEXITCODE` is appended to
the command being run (as in the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands using the local
transport through Bolt. This appends a Powershell snippet to exit with
the correct exit code to commands running on Windows using the local
transport.

Closes puppetlabs#1846

!bug

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
@lucywyman lucywyman self-assigned this Jun 9, 2020
lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 9, 2020
Powershell will [exit 1](PowerShell/PowerShell#11461) whenever the
$LASTEXITCODE is greater than 0, regardless of what the code is,
whenever running a bare command. Powershell exits with the correct exit
code when executing files, or when `exit $LASTEXITCODE` is appended to
the command being run (as in the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands using the local
transport through Bolt. This appends a Powershell snippet to exit with
the correct exit code to commands running on Windows using the local
transport.

Closes puppetlabs#1846

!bug

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 10, 2020
Powershell will [exit 1](PowerShell/PowerShell#11461) whenever the
$LASTEXITCODE is greater than 0, regardless of what the code is,
whenever running a bare command. Powershell exits with the correct exit
code when executing files, or when `exit $LASTEXITCODE` is appended to
the command being run (as in the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands using the local
transport through Bolt. This appends a Powershell snippet to exit with
the correct exit code to commands running on Windows using the local
transport.

Closes puppetlabs#1846

!bug

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 10, 2020
Powershell will [exit 1](PowerShell/PowerShell#11461) whenever the
$LASTEXITCODE is greater than 0, regardless of what the code is,
whenever running a bare command. Powershell exits with the correct exit
code when executing files, or when `exit $LASTEXITCODE` is appended to
the command being run (as in the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands using the local
transport through Bolt. This appends a Powershell snippet to exit with
the correct exit code to commands running on Windows using the local
transport.

Closes puppetlabs#1846

!bug

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 10, 2020
Powershell will [exit 1](PowerShell/PowerShell#11461) whenever the
$LASTEXITCODE is greater than 0, regardless of what the code is,
whenever running a bare command. Powershell exits with the correct exit
code when executing files, or when `exit $LASTEXITCODE` is appended to
the command being run (as in the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands using the local
transport through Bolt. This appends a Powershell snippet to exit with
the correct exit code to commands running on Windows using the local
transport.

Closes puppetlabs#1846

!bug

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
lucywyman added a commit to lucywyman/bolt that referenced this issue Jun 10, 2020
Powershell will [exit 1](PowerShell/PowerShell#11461) whenever the
$LASTEXITCODE is greater than 0, regardless of what the code is,
whenever running a bare command. Powershell exits with the correct exit
code when executing files, or when `exit $LASTEXITCODE` is appended to
the command being run (as in the [execute_process
snippet](https://github.com/puppetlabs/bolt/blob/0d44ce739d4dafcb6d27abd894e230894fdd50e0/lib/bolt/shell/powershell/snippets.rb#L19),
meaning this is only an issue when running commands using the local
transport through Bolt. This appends a Powershell snippet to exit with
the correct exit code to commands running on Windows using the local
transport.

Closes puppetlabs#1846

!bug

* **Return correct exit code when running commands in powershell** ([1846](puppetlabs#1846))

  Bolt will now display the correct exit code when running commands in
  powershell that exit with code > 1.
nicklewis added a commit that referenced this issue Jun 11, 2020
(GH-1846) Exit with correct exit code when running on Windows with local transport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug reports and fixes.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants