Cannot use ${{}} in contexts in shell command

I’m trying to use a custom shell command to set an rc file for bash. What I want to do is:

shell: bash --rcfile ${{ github.workspace }}/.github/workflows/bashrc -eo pipefail {0}

or use a short form like this:

SHELL: bash --rcfile ${{ github.workspace }}/.github/workflows/bashrc -eo pipefail {0}
# sometime later
- name: foo
shell: ${{ env.SHELL }}

In both cases it appears the context cannot be resolved within the shell parameter, as I get this error:

  • Your workflow file was invalid: The pipeline is not valid. .github/workflows/ci.yaml (Line: 23, Col: 14): Unrecognized named-value: ‘env’. Located at position 1 within expression: env.SHELL,.github/workflows/ci.yaml (Line: 40, Col: 14): Unrecognized named-value: ‘env’. Located at position 1 within expression: env.SHELL

I get a similar error for the github context when I try the other method as well.

BTW, it would be handy to have the shell: option at the job level so we can set a default instead of just per-step.

1 Like

When using the shell keyword to specify and set a shell, currently we seems are not able to use variables (such as environment variables, matrix parameters) in the value of the shell keyword.

In addition, the default workspace of the current running job generally is ${{ github.workspace }}. Because the RC file you want to set is contained in the workspace, maybe you can try to only specify the relative path of the RC file instead of the full absolute path.

For example:

shell: bash --rcfile .github/workflows/bashrc -eo pipefail {0}


shell: bash --rcfile ./.github/workflows/bashrc -eo pipefail {0}
1 Like

Custom rcfile setting that worked for me with default bash shell (no override):

  BASH_ENV: .github/workflows/bashrc

Thanks @alun ! I worked around this in my build mainly by duplicating the steps we’d take in the rc file, but this looks like the right solution to me.

1 Like