无法通过Jenkinsfile运行“ fastlane”命令

时间:2018-12-27 18:21:54

标签: android jenkins gradle jenkins-pipeline fastlane

我写了一个Gradle task,它通过命令行执行fastlane supply命令。任务看起来像这样:

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"
}

此任务从运行我的Jenkins从属服务器上的终端成功运行,并以Gradle task的身份通过Android Studio并通过./gradlew uploadToPlayStore的终端成功运行。最初,它无法通过Android Studio终端正常运行,直到我执行了Invalidate Cache and Restart of Android Studio。出现此错误:

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

当前,当我尝试运行Jenkins Multibranch Pipeline时,遇到了以前在Android Studio中遇到的相同错误。根据到目前为止的发现,似乎詹金斯出于某种原因找不到fastlane命令。我尝试为要在其中构建项目的构建节点设置Environment Variable,但是仍然遇到相同的错误。

这是我执行stage任务的Jenkinsfile中的Fastlane

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...'
                    }
                }
            }
        }

更新(1):当在"~/.rvm/rubies/ruby-2.4.2/bin/fastlane", "supply", ...标志处于活动状态下以--debug运行命令时,我得到以下堆栈跟踪:

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)

更新(2):经过大约一天的调试,我发现当我通过gem env的{​​{1}}运行Script Console命令时,获得不同的RUBYGEMS版本,gem路径和shell路径。我目前正在尝试使Jenkins node使用安装在计算机上的Ruby Gems而不是它自己的(或这些行中的某些东西)。

更新(3):经过大约3天的调试,我终于设法弄清楚出了什么问题。问题在于,在运行Jenkins管道作业时,您实际上无法通过标准的Web界面和插件(例如EnvInject)来设置环境变量。另外,Mac OS具有内置的ruby环境,默认情况下,Jenkins节点使用该环境,无法在其上安装Fastlane Gem。

2 个答案:

答案 0 :(得分:0)

您通常需要手动设置PATH,因为Jenkins从站无法获取完整路径。

这可以通过从站的配置页面上的Jenkins仪表板完成(管理Jenkins->管理节点->->配置)。

您可以通过在从站上运行which fastlane来找出fastlane的安装位置。

答案 1 :(得分:0)

解决方案如下:

  1. 在您的Jenkins奴隶上安装RVMRBEnv
  2. 安装Fastlane
  3. 将适当的环境变量添加到您的Jenkinsfile