title: Dynamically retrieve GitHub Actions secret
body: <p>I'm trying to dynamically pull back a GitHub secret using GitHub Actions at runtime:</p>
  
  <p>Let's say I have two GitHub Secrets:</p>
  
  <ol>
  <li>SECRET_ORANGES : "This is an orange secret"</li>
  <li>SECRET_APPLES : "This is an apple secret"</li>
  </ol>
  
  <p>In my GitHub Action, I have another env variable which will differ between branches</p>
  
  <pre><code>env:
    FRUIT_NAME: APPLES
  </code></pre>
  
  <p>Essentially I want to find a way to do some sort of variable substitution to get the correct secret. So in one of my child jobs, I want to do something like:</p>
  
  <pre><code>env:
    FRUIT_SECRET: {{ 'SECRET_' + env.FRUIT_NAME }}
  </code></pre>
  
  <p>I've tried the following approaches with no luck:</p>
  
  <pre><code>secrets['SECRET_$FRUIT_NAME'] }}
  </code></pre>
  
  <p>I even tried a simpler approach without concatenation just to try and get it working</p>
  
  <pre><code>secrets['$FRUIT_NAME'] }}
  </code></pre>
  
  <p>and</p>
  
  <pre><code>{{ secrets.$FRUIT_NAME }}
  
  </code></pre>
  
  <p>None of the above worked.</p>
  
  <p>Apologies if I have not explained this very well. I tried to keep my example as simple as possible.</p>
  
  <p>Anyone have any idea of how to achieve this?</p>
  
  <p>Alternatively, what I am trying to do is to store secrets on a per-branch basis</p>
  
  <p>For example:</p>
  
  <p>In <code>customer1</code> code branch:
  <code>SECRET_CREDENTIAL="abc123"</code></p>
  
  <p>In <code>customer2</code> code branch:
  <code>SECRET_CREDENTIAL="def456"</code></p>
  
  <p>Then I can access the correct value for <code>SECRET_CREDENTIAL</code> depending on which branch I am in.</p>
  
  <p>Thanks!</p>
  
  <p>Update: I'm getting a bit closer to what I am trying to achieve:</p>
  
  <pre><code>name: Test
  
  env:
    CUSTOMER: CUSTOMER1
  
  jobs:
    build:
      runs-on: ubuntu-latest
      env:
        AWS_ACCESS_KEY_ID: ${{ env.CUSTOMER }}_AWS_ACCESS_KEY_ID
      steps:
      - uses: actions/checkout@v2
      - run: |
          AWS_ACCESS_KEY_ID=${{ secrets[env.AWS_ACCESS_KEY_ID] }}
          echo "AWS_ACCESS_KEY_ID = $AWS_ACCESS_KEY_ID"
  </code></pre>