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

Bad command execution with Exec task, overwritten PATH environment variable, and TestKit #12982

Open
v1nc3n4 opened this issue Apr 30, 2020 · 0 comments

Comments

@v1nc3n4
Copy link

v1nc3n4 commented Apr 30, 2020

Hello,

Please find enclosed a demo project demonstrating an incorrect forwarding/usage of the PATH environment variable by the Gradle Runner/TestKit.
Project: gradle-exec.zip

Environment
O/S: Ubuntu 18.04.4 LTS
JDK: OpenJDK 1.8.0_242 64 bits
Gradle: 6.3

Description
The single test class in the project performs the following actions:

  • Create 2 identical shell scripts with the same file name mycommand, that echoes their absolute path and the content of the PATH environment variable. Both scripts are created in 2 temporary directories whose name starts with bin1- prefix, respectively bin2- prefix.
  • Create a build.gradle file with a myTask task based on the Exec type, that simply executes the mycommand command, relying on the PATH environment variable to locate it.
  • Execute test shouldExecCommandInBin1: prepend the PATH environment variable with bin1-... directory, and provide this variable to the Gradle Runner. The expected result here is command bin1-.../ mycommand is executed, which is OK.
  • Execute test shouldExecCommandInBin2: prepend the PATH environment variable with bin2-... directory, and provide this variable to the Gradle Runner. The expected result here is command bin2-.../mycommand is executed, which is KO. Indeed, even if the content of the PATH environment variable seems relevant once in the command shell script, the Gradle Runner executes the bin1-.../mycommand command.

Below you will find the output of a gradlew test command:

$ ./gradlew test
> Task :test
ExecPathTest > shouldRunTaskWithCommandInBin1() STANDARD_OUT
    > Task :myTask
    /tmp/bin1-8749809166213298195/mycommand: PATH=/tmp/bin1-8749809166213298195:...:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    BUILD SUCCESSFUL
     in 6s
    1 actionable task: 1 executed
ExecPathTest > shouldRunTaskWithCommandInBin1() PASSED
ExecPathTest > shouldRunTaskWithCommandInBin2() STANDARD_OUT
    > Task :myTask
    /tmp/bin1-8749809166213298195/mycommand: PATH=/tmp/bin2-8177081762864333825:...:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    BUILD SUCCESSFUL
     in 1s
    1 actionable task: 1 executed
ExecPathTest > shouldRunTaskWithCommandInBin2() PASSED
BUILD SUCCESSFUL in 14s
4 actionable tasks: 3 executed, 1 up-to-date

Maybe I made a mistake, but actually I don't understand why such result. It is also strange for me because the PATH environment variable is relevant once in the shell script.
Thanks in advance for your help!
BR,
Vincent

@v1nc3n4 v1nc3n4 changed the title Bad command resolution with Exec task, PATH environment variable, and TestKit Bad command execution with Exec task, overwritten PATH environment variable, and TestKit Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants