Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Actions: Can not acces values in properties file

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?

like image 902
dudi Avatar asked Jan 20 '26 21:01

dudi


1 Answers

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
...
like image 52
dudi Avatar answered Jan 22 '26 15:01

dudi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!