Reputation: 93
I have 2 repositories secrets in Git Hub: Secret_Key1 and Secret_Key2, I also have a YAML file. Ex:
system1:
port: 3333
user: user1
key: Secret_Key1
system2:
port: 4444
user: user2
key: Secret_Key2
Now, in my workflow I am taking choice input(via workflow dispatch) with system1 or system2, using setup-yq, I can get key values from the above YAML file. Let's say I chose system1 and from the setup-yq step I can get Secret_Key1(secret key name) and I plan to fetch its value into the key variable in GitHub steps, but I cannot use the key to utilize its secret.
My Workflow step Example:
on:
workflow-dispatch:
inputs:
Target_System:
description: 'Target_System'
required: true
default: system1
type: choice
options:
- system1
- system2
jobs:
setup:
runs-on: [hosted-runner]
steps:
- name: setup yq
uses: setup-yq@v2
- name: Extract Value From Config
run:
system_name="${{ inputs.system_name }}"
key=$(yq eval ".${system_name}.key" "config.yaml") #working, it can get secret key name
#I tried several ways below, but none seems to be working
#way 1
echo "key=$key" >> $GITHUB_ENV
echo "${{ secrets[env.key] }}" #didn't worked
#way 2
key=${{ secrets[format('{0}',env.key]) }}
echo "$key" #didn't worked
Note:
Upvotes: -1
Views: 40