Travis CI环境变量“;”预期

时间:2019-11-17 17:35:21

标签: android continuous-integration environment-variables travis-ci

这是我第一次使用TravisCI尝试CI / CD。

我正在尝试对其进行设置,以便对我的API密钥进行加密。我的机器上出现了奇怪的Ruby问题,因此无法通过终端加密密钥,因此需要在存储库设置中定义变量。

  • 我已将API密钥存储为~/.gradle/gradle.properties LUCKY_COINS_API_KEY= "abcd-1234"

  • 然后我通过TravisCI将环境变量添加到我的仓库中,其名称和值与上述相同,我尝试用';'添加它和没有。

  • 在我的应用build.gradle中,有以下几行。

    buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        buildConfigField 'String', 'LUCKY_COINS_API_KEY', apiKey()
    }
    debug {
        minifyEnabled true
        buildConfigField 'String', 'LUCKY_COINS_API_KEY', apiKey()
    }
    

    }

    def apiKey() {
    if (project.hasProperty("LUCKY_COINS_API_KEY")) {
        return project.properties["LUCKY_COINS_API_KEY"]
    } else if (System.getenv("LUCKY_COINS_API_KEY") != null) {
        return System.getenv("LUCKY_COINS_API_KEY")
    } else {
        throw Exceptions("Set API Key")
    }
    }
    

因此,现在当项目基于CI构建时,由于TravisCI无法将值从本地home gradle.properties中提取出来,因此可以访问API密钥。问题是我遇到以下错误:

所有这些都位于远程BuildConfig.java

e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: ';' expected
  public static final String LUCKY_COINS_API_KEY = [secure];
                                                    ^
e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: <identifier> expected
  public static final String LUCKY_COINS_API_KEY = [secure];
                                                           ^
e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: <identifier> expected
  public static final String LUCKY_COINS_API_KEY = [secure];
                                                                ^
e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: illegal start of type
  public static final String LUCKY_COINS_API_KEY = [secure];
                                                                 ^
e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: <identifier> expected
  public static final String LUCKY_COINS_API_KEY = [secure];
                                                                   ^
e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: ';' expected
  public static final String LUCKY_COINS_API_KEY = [secure];
                                                                     ^
e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: illegal start of type
  public static final String LUCKY_COINS_API_KEY = [secure];
                                                                      ^
e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: <identifier> expected
  public static final String LUCKY_COINS_API_KEY = [secure];
                                                                          ^
e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: ';' expected
  public static final String LUCKY_COINS_API_KEY = [secure];
                                                                           ^
e: /home/travis/build/accountName/Lucky-Coins/app/build/generated/source/buildConfig/debug/com/example/luckycoins/BuildConfig.java:14: error: <identifier> expected
  public static final String LUCKY_COINS_API_KEY = [secure];

我无法访问此文件,因此无法调试它。

1 个答案:

答案 0 :(得分:0)

如果要添加字符串作为存储库变量,则必须转引号。

因此请确保放置“ \” API_KEY_HERE \””