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

Is it possible to use a Gradle config variable in my gitlab-ci file?

我想知道是否可以在我的 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
    }
}

在我的 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.

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

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

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

这样我就可以访问文件中带有 $VERSION 的 versionName。