Here is my requirement. I have separate GitHub secrets created for each environment.
For eg in GitHub secrets:
STAGING_USERNAME -> <SOME_VALUE>
PROD_USERNAME -> <SOME_VALUE>
I want to construct a new variable and set it in GitHub env like below
name: Build and Deploy to CAA Backend
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
infraEnv:
description: 'Env (staging/prod)'
required: true
default: 'staging'
jobs:
setup-build-publish:
name: Test, Build, Deploy, Notify
runs-on: ubuntu-latest
steps:
name:
run: |
echo "USERNAME=${{secrets.${{github.event.inputs.infraEnv}}_username}}" >> $GITHUB_ENV
But this is throwing a syntax error. How to fix this?
You can do this with the format function:
${{ secrets[format('{0}_username', github.event.inputs.infraEnv)] }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With