是否可以在我的 gitlab-ci 文件中使用 Gradle 配置变量?

Tuc*_*uco 0 continuous-integration gradle gitlab gitlab-ci

我想知道是否可以在我的 gradle 文件的 DefaultConfig 中使用 versionName 变量:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

defaultConfig {
    applicationId "app"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

    lintOptions {
        abortOnError false
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的 gitlab-ci 文件中:

stages:
    - build

release:
  stage: build
  only:
    - release
  script:
    - ./gradlew assembleRelease
    # Here I need to use the value of versionName in my gradle file.
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法可以做到这一点?

Tuc*_*uco 5

我最终使用 gitlab-ci 文件中的命令行脚本来完成它:

export VERSION = $(grep -E "versionName " app/build.gradle | cut -d "\"" -f2)
Run Code Online (Sandbox Code Playgroud)

这样我就可以在文件中使用 $VERSION 访问 versionName 。