Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 5

Dynamically Select Secrets

Currently have the yaml below.  For <KEY HERE> I was looking for a way to dynamically select the secret based on the matrix environment its running in. Can be as simple as of passing {{ $matrix.env }} and a hardcoded string like "API_KEY". Any thoughts on if this is possible?

 

name: Deployment
on:
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Run Deployment
        run: |
          echo hello
        env:
          VAR_API_KEY: <KEY HERE>
4 Replies
Pilot Lvl 1
Message 2 of 5

Re: Dynamically Select Secrets

You might need to check Contexts and expression syntax for GitHub Actions here

As from what I know secrets are only available within the workflow steps.

 

 

------------------------

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Highlighted
GitHub Partner
Message 3 of 5

Re: Dynamically Select Secrets

I noticed that you also reported the same question in another ticket linked here:

https://github.community/t5/GitHub-Actions/Secrets-in-matrix/m-p/42613/highlight/false#M5048

I have added a reply in that ticket.

Highlighted
Copilot Lvl 2
Message 4 of 5

Re: Dynamically Select Secrets

Hey @BrightRan this ones a bit different, this is around dynamically selecting a secret. The other was around referencing secrets in a matrix

Highlighted
GitHub Partner
Message 5 of 5

Re: Dynamically Select Secrets

According to your reply, I have two workarounds as reference:

  • If you wants to execute multiple combinations of the configurations in each workflow run, you can use matrix job.

example01.PNG

  • If you wants to execute only one combination of the configurations in each workflow run, you can use the if conditional.

example02.PNG