How to run gh auth login --with-token on Windows with PowerShell?
#8616
Replies: 4 comments 2 replies
|
To run gh auth login --with-token on Windows with PowerShell in a GitHub Actions workflow, you can use the following example: |
|
The PowerShell shape does work, but the syntax is PowerShell-specific. I just verified that piping a value into: gh auth login --with-tokenis accepted as standard input by So the practical forms are: If the token is already in an environment variable: $env:GH_TOKEN | gh auth login --with-tokenIf it is in a file: Get-Content .\mytoken.txt | gh auth login --with-tokenThe main thing to avoid is mixing cmd redirection syntax into PowerShell. So my short answer would be:
|
|
The errors are coming from PowerShell, not from
# from an environment variable
$env:GH_TOKEN | gh auth login --with-token
# or from a file
Get-Content .\token.txt | gh auth login --with-tokenIf this is inside GitHub Actions (your - shell: pwsh
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }} # or ${{ github.token }}
run: gh pr list # any gh command — no login step neededA couple of notes:
|
|
PowerShell does not support bash-style Recommended: pipe the token (works in PowerShell)$env:GH_TOKEN = "${{ secrets.GH_TOKEN }}"
echo $env:GH_TOKEN | gh auth login --with-tokenOr inline in a workflow step: - name: Authenticate gh
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: echo $env:GH_TOKEN | gh auth login --with-tokenAlternative: here-string (also PowerShell-native)@"
${{ secrets.GH_TOKEN }}
"@ | gh auth login --with-tokenWhat not to do on Windows
Verify authgh auth status
gh api user --jq .loginTip for GitHub Actions on
|
Uh oh!
There was an error while loading. Please reload this page.
I can't get it to work in any way:
echo ${{ secrets.GH_TOKEN }} | gh auth login --with-tokenresults inA positional parameter cannot be found that accepts argument 'auth'.Or `Cannot run a document in the middle of a pipeline: C:\hostedtoolcache\windows\gh-cli\2.32.0\x64\bin\gh.cmd /c "gh auth login --with-token < $(echo ***)"results inThe system cannot find the file specified.How do I get it to work with PowerShell?
All reactions