Secret Gralde Properties - GitLab CI

In my Android Studio project, in app/build.gradle, I’m using some values coming from the gradle.properties file in my local .gradle directory. I have used this setup since I do not want to commit these values to the repo.

How can I access these values when using GitLab CI?

I tried adding the values to Settings > CI / CD > Variables but the build.gradle does not seem to see those variables. Build always fails with the error “Could not get unknown property.”

This is how I used properties in my app/build.gradle:

This is how I have set the variables in GitLab CI/CD settings:

This is what I get when running GitLab CI/CD:

I’m following this https://about.gitlab.com/blog/2018/10/24/setting-up-gitlab-ci-for-android-projects/ post to setup my pipeline. The .gitlab-ci.yml script in this post is used without any changes in my project.

In your .gitlab-ci.yml reference, you can add a -P option in ./gradlew assembleDebug to add a project property.

  ...
  script:
    - ./gradlew assembleDebug -P<variable_name_in_project>=<variable_name_in_cicd_variables>
  ...

In your case,

  ...
  script:
    - ./gradlew assembleDebug -Pcom_incylabs_incypos_API_KEY_MAIL_CHIMP=com_incylabs_incypos_API_KEY_MAIL_CHIMP
  ...

You can as much -P's as needed.

1 Like

Thanks, this comment here saved me a lot of time :slight_smile: