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

Fix for Batch scripts not properly signalling a failure in a pipeline #4784

Closed

Conversation

jasonmarcher
Copy link

@jasonmarcher jasonmarcher commented Mar 20, 2018

The Windows shell pipeline will not detect a failure when using 'exit /b 1'. Instead generate a real failure that will cause the pipeline to behave correctly.

Signed-off-by: Jason Archer jasonmarcher@gmail.com

Context

One of our developers noticed that gradlew someTaskThatDoesNotExist && echo Success does not behave correctly on Windows. The echo will happen even though the Gradle invocation failed.

Here is a StackOverflow thread about the issue and the source of the solution used here. https://stackoverflow.com/questions/4632891/exiting-batch-with-exit-b-x-where-x-1-acts-as-if-command-completed-successfu

Contributor Checklist

  • Review Contribution Guidelines
  • Make sure that all commits are signed off to indicate that you agree to the terms of Developer Certificate of Origin.
  • Check "Allow edit from maintainers" option in pull request so that additional changes can be pushed by Gradle team
  • Provide integration tests (under <subproject>/src/integTest) to verify changes from a user perspective
  • Provide unit tests (under <subproject>/src/test) to verify logic
  • Update User Guide, DSL Reference, and Javadoc for public-facing changes
  • Ensure that tests pass locally: ./gradlew <changed-subproject>:check

Gradle Core Team Checklist

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation
  • Recognize contributor in release notes

… when using 'exit /b 1'. Instead generate a real failure that will cause the pipeline to behave correctly.

Signed-off-by: Jason Archer <jasonmarcher@gmail.com>
@jasonmarcher
Copy link
Author

Repaired failing test. It really needs to be written better. I may do that.

@jasonmarcher
Copy link
Author

Not sure why the diff is showing the whole test class changing, I probably got the line endings changed. Will investigate later.

The real change is a single line in the line ending test.

…Linux line endings present.

Signed-off-by: Jason Archer <jasonmarcher@gmail.com>
@jasonmarcher jasonmarcher force-pushed the jasonmarcher/fix-batch-failure branch from 5aec1d0 to 819f46d Compare March 22, 2018 18:07
@big-guy big-guy added the @core Issue owned by GBT Core label Jun 19, 2019
@big-guy
Copy link
Member

big-guy commented Mar 10, 2020

Thanks for your contribution. I'm sorry we didn't get back to you in a reasonable amount of time. If someone thinks this change is still valuable, please submit a new PR.

Thanks again!

@big-guy big-guy closed this Mar 10, 2020
mataha added a commit to mataha/gradle that referenced this pull request May 8, 2024
Windows script `gradlew.bat` executes Gradle within its own, batch context.
This causes every locally declared variable to be visible to underlying `java`
process, *potentially* leaking information about used options and classpath.

To mitigate this, we jump to a non-existent label, forcing `cmd.exe` to stop
processing the script, yet run the remaining commands within the current line
in parent (most likely command-line when invoking `gradlew` directly) context.
This introduces a harmless side-effect in form of corrupting the current title
of the window `cmd.exe` was invoked in, thus it is reset to the default value.

This provides a few side benefits:

  - no more 'Terminate batch job (Y/N)?' prompt
  - `call ` and `call` are used to directly set exit code, resolving gradle#4784
  - both sh and `cmd.exe` scripts become synchronized in terms of mechanism
    used to execute JVM as well as environment sanitization

Issue: gradle#10463

Signed-off-by: mataha <mataha@users.noreply.github.com>
mataha added a commit to mataha/gradle that referenced this pull request May 17, 2024
Windows script `gradlew.bat` executes Gradle within its own, batch context.
This causes every locally declared variable to be visible to underlying `java`
process, *potentially* leaking information about used options and classpath.

To mitigate this, we jump to a non-existent label, forcing `cmd.exe` to stop
processing the script, yet run the remaining commands within the current line
in parent (most likely command-line when invoking `gradlew` directly) context.
This introduces a harmless side-effect in form of corrupting the current title
of the window `cmd.exe` was invoked in, thus it is reset to the default value.

This provides a few side benefits:

  - no more 'Terminate batch job (Y/N)?' prompt
  - `call ` and `call` are used to directly set exit code, resolving gradle#4784
  - both sh and `cmd.exe` scripts become synchronized in terms of mechanism
    used to execute JVM as well as environment sanitization

Issue: gradle#10463

Signed-off-by: mataha <mataha@users.noreply.github.com>
mataha added a commit to mataha/gradle that referenced this pull request May 17, 2024
Windows script `gradlew.bat` executes Gradle within its own, batch context.
This causes every locally declared variable to be visible to underlying `java`
process, *potentially* leaking information about used options and classpath.

To mitigate this, we jump to a non-existent label, forcing `cmd.exe` to stop
processing the script, yet run the remaining commands within the current line
in parent (most likely command-line when invoking `gradlew` directly) context.
This introduces a harmless side-effect in form of corrupting the current title
of the window `cmd.exe` was invoked in, thus it is reset to the default value.

This provides a few side benefits:

  - no more 'Terminate batch job (Y/N)?' prompt
  - `call ` and `call` are used to directly set exit code, resolving gradle#4784
  - both sh and `cmd.exe` scripts become synchronized in terms of mechanism
    used to execute JVM as well as environment sanitization

Issue: gradle#10463

Signed-off-by: mataha <mataha@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@core Issue owned by GBT Core in:wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants