Write Secrets to File

I’m trying to write an enviromental variable file that was stored in a secret in my repository, however, I can’t confirm it’s being written correctly. I know there’s an error when loading it but I can’t tell if it’s not formatted correctly, or what it is.

Here is how I’m trying to write the file: 

- run: printf $DEV_ENV_FILE >> src/.env
   - run: printf $DEV_ENV_FILE
   - run: cat src/.env 

Hi @destinybonavita , 

You could upload the env file as an artifact , then you could see the secret variable value after downloading the artifact. 

Also, you need to use ${{secrets.variablename }} syntax to get secret variable value, please see my example:

name: get secrets
on:
  push:
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: print secrets
      run: |
          echo $DEV_ENV_FILE >> src/.env
          cat src/.env
      shell: bash
      env:
        DEV_ENV_FILE : ${{secrets.SECRET1}}
    - name: Upload a Build Artifact
      uses: actions/upload-artifact@v2
      with:
       name: DEV_ENV_FILE
       path: src/.env

Hi @yanjingzhu! Sorry for the late response. When I run echo it removes all the linebreaks in the secret I stored. However, when I run printf in replacement of echo it’s only printing the first line to the file.

Turns out my problem was that I wasn’t wrapping the env variable in quotes when running printf. That fixed it