I want to access my secret from a yml file. I am saving secrets like this:
USER_NAME: secrets.AZURE_ID
password: secrets.pass_SECRET
Then I am loading them in a step like this:
- name: read yml file python
run: |
pip install pyyaml
ENV_VAR=$(python3 -c "import yaml; from yaml import Loader; print(yaml.load(open('./config.yml', 'r'), Loader=Loader))")
echo "ENV_VAR=$ENV_VAR" >> $GITHUB_ENV
I try to access the value of secrets but unfortunately, it's not working. It says it can not read the username.
Here is how I access the secrets:
- name: Login to Azure Registry
uses: azure/docker-login@v1
env:
INTERM_username: ${{ secrets[ fromJSON(env.ENV_VAR).USER_NAME ] }}
INTERM_password: ${{ secrets[ fromJSON(env.ENV_VAR).password ] }}
with:
username: ${{ env.INTERM_username }}
password: ${{ env.INTERM_password }}
I also tried fromJSON(env.ENV_VAR).USER_NAME
:
- name: Login to Azure Registry
uses: azure/docker-login@v1
env:
INTERM_username: ${{ fromJSON(env.ENV_VAR).USER_NAME }}
INTERM_password: ${{ fromJSON(env.ENV_VAR).password }}
with:
username: ${{ env.INTERM_username }}
password: ${{ env.INTERM_password }}
But it's not getting the value from secret. Both INTERM_username
and INTERM_password
are giving empty strings. I guess they cannot read the secret. Is there any other way? I need to save the name of the secret as I want to access them based on the branch it triggered on.