首页 > 解决方案 > react native bundle 没有采用 Jenkins 提供的环境变量

问题描述

我有一份 jenkins 工作,负责从 react-native 项目构建 android。管道脚本运行良好,但当它到达时react-native-bundle它无法告诉我couldn't find environment variable no .env present

这是我在詹金斯中使用的脚本

pipeline {
agent any
stages {
  stage("Checkout") {
      steps {
          echo "Environment: ${env.ENVIRONMENT}"
          checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/pipeline']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'p_rad', url: 'https://***.com/myprj.git']]]
      }
  }
  stage('Dependancies and Bundling') {
      steps {
          echo 'installing dependancies'
          nodejs('NodeJS_7.0.0') {
              sh label: '', script: 'npm install -g react-native-cli'
              sh label: '', script: 'npm install'
              sh label: '', script: 'npm run bundle-android-release'
              sh label: '', script: 'cd android'
              sh label: '', script: 'chmod +x gradlew'
              sh label: '', script: './gradlew clean assembleRelease'
          }
        }
      }
  }
}

echo ${env.ENVIRONMENT}当我从 Jenkins 触发参数化构建时,该命令打印 dev 并且一个参数是 ENVIRONMENT=dev

但是 react-native-bundle 命令无法获取这些值,并且错误表示指定位置下没有 .env 文件。

当我尝试writeFile file: '.env', text: "some parameters=00"应用程序时(尝试将一个参数写入 .env 文件)

标签: react-nativejenkinsjenkins-pipeline

解决方案


推荐阅读