Accessing GitHub Action variables

Posted: | Tags: til github

Within a repository’s settings tab under Security you can set an Actions secrets and variables. A secret is encrypted and created for use with sensitive data whereas a variable is displayed as plain text. I intended to use a repository variable as an environment variable for a Python script within one of my workflows and the GitHub documentation was not very useful in describing how to accomplish that.

Thanks to mbaum0 on this discussion thread I learned that you can access variables with the vars context.1 Using vars I can then set the variable within the environment of the workflow to be used by the Python script. In the example below I have set USERNAME as an Action variable and then set it as an environment variable within the workflow.

env:
  USERNAME: ${{ vars.USERNAME }}

This technique is used in my activity-rss-for-anilist repository.

There are many more examples online of how to access secrets but in case you don’t know it can done via the secrets context. For example, ${{ secrets.USERNAME }} if USERNAME was set an Action secret.


  1. I also learned that I wasn’t the only one that found the GitHub documentation confusing regarding this. ↩︎


Related ramblings