Skip to content

Accessing secrets by index using an environment variable #25171

Answered by Yanjingzhu
nilsdebruin asked this question in Actions
Discussion options

You must be logged in to vote

Hi @nilsdebruin,  

Accessing secrets by index using an environment variable is not supported.
As a workaround , you could add another step with if conditional for non-production . And you could use secrets.PROD directly when set a step environment variable. 

name: get secrets variable name from another env
on: push
jobs:
  get-secret:
    runs-on: ubuntu-latest
    steps:
    - name: Set env to production
      if: endsWith(github.ref, '/master')
      run: echo $environment
      env:
        environment: ${{secrets.PROD}}
    - name: Set env to non production
      if: "!endsWith(github.ref, '/master')"
      run: echo $environment
      env:
        environment: ${{secrets.TEST}}

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants