title: Can't run "fastlane" command via Jenkinsfile
body: <p>I wrote a <code>Gradle task</code> which executes the <code>fastlane supply</code> command via the command line. The task looks like this:</p>
  
  <pre><code>task uploadToPlayStore(type: Exec) {
      group = "upload"
      commandLine "fastlane", "supply",
              "--aab", "$project.rootDir/app/build/outputs/bundle/upload/${archiveFile}.aab",
              "--mapping", "$project.rootDir/app/build/outputs/mapping/upload/mapping.txt",
              "--skip_upload_apk", "true",
              "--skip_upload_metadata", "true",
              "--skip_upload_images", "true",
              "--skip_upload_screenshots", "true",
              "--track", "internal",
              "--package_name", "$appPackage",
              "--json_key", "~/Documents/key.json"
  }
  </code></pre>
  
  <p>This task runs successfully from the terminal on the Jenkins slave I'm running it on, and via Android Studio as a <code>Gradle task</code> and via its terminal by <code>./gradlew uploadToPlayStore</code>. At first it wasn't running properly via Android Studio's terminal until I did a Invalidate Cache and Restart of Android Studio. It was giving this error:</p>
  
  <pre><code>org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:uploadToPlayStore'.
  ...............
  Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'fastlane''
  ...............
  Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'fastlane'
  ...............
  Caused by: java.io.IOException: Cannot run program "fastlane" (in directory "/Users/..."): error=2, No such file or directory
  ...............
  Caused by: java.io.IOException: error=2, No such file or directory
  </code></pre>
  
  <p>Currently when I try to run my Jenkins Multibranch Pipeline I get the same error I previously got in Android Studio. From what I've found so far, it appears that Jenkins can't find the <code>fastlane</code> command for some reason. I tried setting an <code>Environment Variable</code> for the build Node where I'm building my projects, but I still get the same error.</p>
  
  <p>This is the <code>stage</code> in the <code>Jenkinsfile</code> where I run my <code>Fastlane</code> task:</p>
  
  <pre><code>stage('Upload To Google Play Store') {
              steps {
                  script {
                      if (env.BRANCH_NAME.startsWith("release")) {
                          sh './gradlew uploadToPlayStore --stacktrace'
                      } else {
                          echo 'Skipping stage since we\'re not on a release branch...'
                      }
                  }
              }
          }
  </code></pre>
  
  <p><strong>Update (1):</strong> When running the command as <code>"~/.rvm/rubies/ruby-2.4.2/bin/fastlane", "supply", ...</code> with the <code>--debug</code> flag active I get the following stacktrace:</p>
  
  <pre><code>22:54:51.135 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
  22:54:51.137 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command '/Users/bild_nachine/.rvm/rubies/ruby-2.4.2/bin/fastlane'.
  22:54:51.147 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTED
  22:54:51.147 [INFO] [org.gradle.process.internal.DefaultExecHandle] Successfully started process 'command '/Users/bild_nachine/.rvm/rubies/ruby-2.4.2/bin/fastlane''
  22:54:51.148 [DEBUG] [org.gradle.process.internal.ExecHandleRunner] waiting until streams are handled...
  22:54:51.150 [ERROR] [system.err] env: ruby_executable_hooks: No such file or directory
  22:54:51.152 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
  22:54:51.152 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command '/Users/bild_nachine/.rvm/rubies/ruby-2.4.2/bin/fastlane'' finished with exit value 127 (state: FAILED)
  </code></pre>
  
  <p><strong>Update (2):</strong> After about a day of debugging I found out that when I run the <code>gem env</code> command via the <code>Script Console</code> of the <code>Jenkins node</code> I get a different RUBYGEMS version, gem paths and shell paths. I'm currently trying to make the <code>Jenkins node</code> use the Ruby Gems installed on the machine and not its own (or something in those lines).</p>
  
  <p><strong>Update (3):</strong> After about 3 days of debugging I finally managed to figure out exactly what's wrong. The problem is that when running a Jenkins pipeline job, you can't really set the environment variables via the standard web interface and plugins (like <a href="https://wiki.jenkins.io/display/JENKINS/EnvInject+Plugin" rel="nofollow noreferrer">EnvInject</a>). Also Mac OS has a built-in ruby environment, which is used by the Jenkins node by default, on which I couldn't install the Fastlane Gem. </p>