3

I have some problem to acces secrets variables in build.gradle file. I've defined two secrets in Github repo settings: PUBLIC_API_KEY and PRIVATE_API_KEY

In my actions.yml file I read them from the secrets, decode and write into a apikey.properties file

name: My fancy app 

on: [ push, pull_request ]

defaults:
  run:
    shell: bash

jobs:

  build:

    runs-on: ubuntu-latest

    steps:
      - name: Clone Repo
        uses: actions/checkout@v1

      - name: Acces API Public Key
        env:
          PUBLIC_API_KEY: ${{ secrets.PUBLIC_API_KEY }}
        run: echo "$PUBLIC_API_KEY" | base64 -d > ./apikey.properties

      - name: Acces API Private Key
        env:
          PRIVATE_API_KEY: ${{ secrets.PRIVATE_API_KEY }}
        run: echo "$PRIVATE_API_KEY" | base64 -d > ./apikey.properties

In my build.gradle I create a properties object from the apikey.properties file and try to read the variables, that where saved in the previous step. This is what is looks like in my build.gradle file

def apikeyPropertiesFile = rootProject.file("apikey.properties")
def apikeyProperties = new Properties()
try {
    apikeyProperties.load(new FileInputStream(apikeyPropertiesFile))
    println("Private Key value" + apikeyProperties['PRIVATE_API_KEY'])
    println("Public Key value" + apikeyProperties['PUBLIC_API_KEY'])
} catch(Exception exception) {
    println("Error by loading properties file" + exception.message)
}
....

buildConfigField("String", "PRIVATE_API_KEY", apikeyProperties['PRIVATE_API_KEY'])
buildConfigField("String", "PUBLIC_API_KEY", apikeyProperties['PUBLIC_API_KEY'])

The build is failing because both apiKeyProperties values are null.

Can somebody tell me, why the values are null?

dudi
  • 5,523
  • 4
  • 28
  • 57

1 Answers1

2

Thanks to this post I found out, that the keys were missing in the apikey.properties file. This is how my fix looks like:

....
 - name: Acces API Keys
        run: |
          touch apikey.properties
          echo PUBLIC_API_KEY=${{ secrets.PUBLIC_API_KEY }} >> apikey.properties
          echo PRIVATE_API_KEY=${{ secrets.PRIVATE_API_KEY }} >> apikey.properties
          cat apikey.properties
...
dudi
  • 5,523
  • 4
  • 28
  • 57