简体   繁体   中英

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.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM