0

I'm currently working on a Gradle project in OSX My function in a .gradle file looks like this

ext.MyFunction = {

     def fastlaneCommand = [
             'fastlane',
             '-version'
     ]

     def stdout = new ByteArrayOutputStream()

     exec {
         ignoreExitValue true
         standardOutput stdout
         workingDir PathsModel.instance.GetDeployerRoot()
         commandLine fastlaneCommand
         LOG.WARN("YOUR CLI COMMAND: " + commandLine)
     }
     println "Output:\n$stdout"
}

And then in 'build.gradle'

task jenkins_deploy() {
    doFirst {
        MyFunction()
    }
}

When it comes time for commandLine to be executed This outputs:

W A R N I N G:  YOUR CLI COMMAND: [fastlane, -version]

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':jenkins_deploy'.
> A problem occurred starting process 'command 'fastlane''

I know for a fact that fastlane is in my path as '$HOME/.fastlane/bin' which is where the executable is located. And if I simply open Terminal and type

'fastlane -version'

from any directory, fastlane tools start-up and do what they're supposed to be doing.

I suppose my question is: What are the possible differences between me opening a terminal and inputting the command manually, and me asking Gradle to do the exact same thing using 'exec'? Am I misunderstanding what 'exec' and 'commandLine' actually do?

Some info on 'fastlane' is that it's using Ruby, which i don't know a lot about. This may prove relevant.

EDIT: I have attempted 'version' the 2nd element in the fastlaneCommand array, as both 'version' and '-version'

EDIT 2 (ACTUAL SOLUTION): Although the marked answer below is a definite workaround, the solution Actual solution has the full reason as to why this happens and why it works.

Guy Joel McLean
  • 1,019
  • 4
  • 12
  • 34
  • I suppose it should be: `['sh', 'fastlane', '-version']`. – Opal Nov 15 '17 at 14:52
  • @Opal Excellent, as that's helped me get past this part of the execution :) However, I don't have to include 'sh' in the terminal. Would you also happen to know why this might be? – Guy Joel McLean Nov 15 '17 at 14:57
  • Also if you'd like to make that comment an Answer, I can mark it as correct. (Unless something more explanatory comes along) – Guy Joel McLean Nov 15 '17 at 14:59
  • Have not the link under my arm, but if you omit `sh` it would be executed as a script located in current directory (or configured as the second argument). If you prefix it with `sh` it will be executed with shell and $PATH variable. – Opal Nov 15 '17 at 15:04

1 Answers1

3

TL;DR

I suppose it should be:

['sh', 'fastlane', '-version']

Explanation:

Have not the link under my arm, but if you omit sh it would be executed as a script located in current directory (or directory configured as the second argument). If you prefix it with sh it will be executed with shell and $PATH variable.

Opal
  • 81,889
  • 28
  • 189
  • 210