Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass GitHub secrets as parameters to powershell script

Trying to pass GitHub secrets to powershell script as parameters but getting *** while executing workflow and it failed:

- name: Connecting to shared drive
  env:
    username: ${{secrets.TEST_USERNAME }}
    password: ${{secrets.TEST_PASSWORD }}
  run: ${{ github.workspace }}\Connect-Drive.ps1 ${{ env.username }} ${{ env.password }}

Getting this error while executing:

The term '***' is not recognized as a name of a cmdlet, function, script file, or executable
like image 743
Sagar Avatar asked Sep 15 '25 09:09

Sagar


1 Answers

Regarding those asterisks ***, according to Accessing your secrets:

Warning: GitHub automatically redacts secrets printed to the log ...

So, those secrets are automatically being redacted in logs.

After setting the secrets as environment variables using env, you can use those directly with $Env:<variable> syntax instead of using ${{ env.variable }}:

- name: Connecting to shared drive
  env:
    username: ${{ secrets.TEST_USERNAME }}
    password: ${{ secrets.TEST_PASSWORD }}
  run: |
    "$Env:GITHUB_WORKSPACE\Connect-Drive.ps1" "$Env:username" "$Env:password"

Need double quotes around $Env:<variable> to be expandable.

See the Default environment variables for GITHUB_WORKSPACE.

If you do use the env context, make sure to use quotes. In this case, prefer single quotes as the values may contain literals expandable by the shell. See the Quoting Rules for Powershell 7.2 for more details as GHA-hosted Windows runners have Powershell 7.2.10 preinstalled.

like image 55
Azeem Avatar answered Sep 17 '25 00:09

Azeem