Ashwin
Ashwin

Reputation: 13537

Environtment variable via github secrets

I have a scala repo on github with has the scala work flow in scala.yml. One of my test requires a special key to be available. But I can't hard code it into source code because of privacy reasons. So, I added the key to Secrets section in Settings. The section states

Secrets are environment variables that are encrypted and only exposed to selected actions. Anyone with collaborator access to this repository can use these secrets in a workflow.

Secrets are not passed to workflows that are triggered by a pull request from a fork.

But when I do try to get the key in my code(in the test) it comes out as blank.

System.getenv("MY_KEY") //MY_KEY is added to the Secrets in Settings of the repo

Also, this workflow is NOT triggered by a pull request from a fork.

Upvotes: 1

Views: 747

Answers (1)

Ashwin
Ashwin

Reputation: 13537

You would need to set it in the set it in the environment variable your work flow as given here. If the variable name in Secrets is MY_KEY then in the work flow you can access it as {{ secrets.MY_KEY }}

Example

    - name: Run tests
      env:
        MY_KEY: ${{ secrets.MY_KEY }}
      run: sbt test

This will set the environment variable MY_KEY and can be accessed via System.getenv("MY_KEY")

Upvotes: 2

Related Questions