google / secrets-gradle-plugin

A Gradle plugin for providing your secrets to your Android project.
Apache License 2.0
1.13k stars 99 forks source link

CI Configuration for Build-Variant Specific Properties #70

Closed malenalbc closed 6 months ago

malenalbc commented 10 months ago

Followed the notes in the docs and created three files: test.properties, staging.properties, production.properties. They work properly locally.

Now, on the CI (Bitbucket, yml), I have a first step on pipelines that dumps the keys into each build variant file, like this:

- step: &Create-Test-properties
    name: Create-Test-properties
    script:
       - echo API_KEY=$MY_SECRET_VAR > test.properties
    artifacts:
       - test.properties

...

Problem is, the error seem to imply that the plugin will go to local.properties and ignore the build-variant files:

Failed to query the value of property 'buildFlowServiceProperty'.

> Could not isolate value () of type BuildFlowService.Parameters

   > A problem occurred configuring project ''.

      > Failed to notify project evaluation listener.

         > The file '.../local.properties' could not be found

Is there a step I'm missing? Configuration options only mentions defaultPropertiesFileName for CI but then it'll use the default file, not the specific ones.

JeromeCHA commented 9 months ago

We are also having the same problem... 🤔

MariusTGLAB commented 6 months ago

yeah same here

malenalbc commented 6 months ago

It's been a while and I don't remember exactly how I made it work, but after some tinkering it did run on the CI properly. I added logs in the bash script to see if the flavour file was really being created or populated properly and it wasn't, so hopefully this will be a tip for people.

Leaving my setup, also, in case it helps:

build.gradle

    secrets {
        defaultPropertiesFileName = 'local.defaults.properties'
    }

I have three files in the project root directory: local.defaults.properties, test.properties, staging.properties, production.properties (The flavour ones are git ignored).

In my yml file:

- step: &Create-Test-properties
    name: Create-Test-properties
    script:
      - echo API_KEY1=$MY_SECRET_VAR1 > test.properties
      - echo API_KEY2=$MY_SECRET_VAR2 >> test.properties
    artifacts:
      - test.properties

(...)

pipelines:
  "{branch}":
    - step: *(...)
    - step: *Create-Test-properties
    - step: *(...)

Also closing this since it feels it was more of a yml configuration issue, not a plugin one.