1

I'm using a gradle plugin written in Kotlin which seems to toggle between flawless victory and disastrous failure and I can't find out why.

Code snippet:

project.exec {
    val command = "aws ssm get-parameter --name /config/testconfig/secrets --with-decryption"
    commandLine(command.split(" "))
    standardOutput = FileOutputStream(secretsJson)
}

This does work from time to time and downloads the Systems Manager properties to a JSON file and all of a sudden doesn't anymore. It's unable to resolve the path to aws, even though /usr/local/bin is in the PATH. The binary is found in /usr/local/Cellar/awscli/1.16.250/libexec/bin/aws though and linked in /usr/local/bin. If called directly the command can be executed without issues.

I've checked the environment variables of both my terminal and my local gradle wrapper and PATH is exactly the same in both.

My colleague is able to run both on his machine (both on macOS).

Any ideas? I'm ... exhausted.

madhead
  • 31,729
  • 16
  • 153
  • 201
Ben
  • 188
  • 4
  • 15
  • 1
    Does this answer your question? [How to permanently set $PATH on Linux/Unix?](https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux-unix) – Martin Zeitler Feb 13 '20 at 12:45
  • 1
    A system-wide `$PATH` should be known to every user. Just try `val command="echo $PATH"` or `\$PATH` (this value is merged from system-wide and user-specific). "All of a sudden doesn't work anymore" likely means the `$PATH` had changed - or running is as another user. – Martin Zeitler Feb 13 '20 at 12:48
  • I had edited my ~/.zshrc (macOS) and the Path had been unchanged. It just stopped working in gradle. I've added the absolute path to my aws binary and restarted my system several times, since then it didn't happen anymore. We'll see ... Thanks! – Ben Feb 13 '20 at 17:49

1 Answers1

1

I've checked the environment variables of both my terminal and my local gradle wrapper and PATH is exactly the same in both.

project.exec will spawn another process, with it's own shell and environment. And that process may not inherit the PATH in a way you expect it. You can check that by printing out the environment from inside that process (commandLine("printenv")). Make sure that AWS CLI is still on the PATH.

madhead
  • 31,729
  • 16
  • 153
  • 201
  • I had created a gradle task to print the current gradle environment variables and the path has been the same. I've added the absolute path to aws to the path now and that issue didn't occur since. I'm just confused on how (or why) it occured in the first place. Thanks for your help! – Ben Feb 13 '20 at 17:46