Is there a way to authenticate programmatically using the GitHub Copilot CLI for Enterprise Cloud customers? #198700
Replies: 5 comments 2 replies
-
|
Hey YuriBreion1. From the behavior you’re seeing, it looks like the Copilot CLI is not picking up the COPILOT_GITHUB_TOKEN environment variable and is falling back to the interactive device-flow authentication process. A few things I’d check:
My suspicion is that the issue is less about GitHub Actions and more about how the Copilot CLI currently handles authentication. If the CLI only supports user-based authentication through the device flow, then running it non-interactively inside Actions may not be supported yet, even though a token is available. I’d be interested to hear from the GitHub team whether fully non-interactive authentication for Copilot CLI in Actions workflows is officially supported today, and if so, what token type and login flow are expected. |
Beta Was this translation helpful? Give feedback.
-
|
Hey @Luke-Corwin, thank you for sharing your thoughts.
I think it works if you use the public cloud on GitHub, but the GitHub Copilot CLI is not ready for such interaction when it comes from the Enterprise Cloud. |
Beta Was this translation helpful? Give feedback.
-
|
Yes. For GitHub Copilot CLI Enterprise Cloud customers, programmatic (non-interactive) authentication is supported and is the recommended approach for automation, CI/CD pipelines, containers, and headless environments. Option 1: Use an environment variable (recommended) Set one of the supported environment variables: export COPILOT_GITHUB_TOKEN=<your_token> or export GH_TOKEN=<your_token> or export GITHUB_TOKEN=<your_token> |
Beta Was this translation helpful? Give feedback.
-
|
Thank you @mitrajotiprova-droid for your feedback, but the result is the same, no success: This is the log from the workflow: The workflow job: jobs:
copilot_cli_test:
name: Send test message
runs-on: ubuntu-latest
env:
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
steps:
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ inputs.node_version }}
- name: Install Copilot CLI
run: npm install -g @github/copilot
- name: Run Copilot CLI
env:
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
run: |
export COPILOT_GITHUB_TOKEN=${{ secrets.COPILOT_GITHUB_TOKEN }}
copilot login --host https://mycompany.ghe.com
copilot -p "Review the git log for this repository and write a bullet point summary of all code changes that were made today, with links to the relevant commit on GitHub. Above the bullet list give a description (max 100 words) summarizing the changes made. Write the details to summary.md" --allow-tool='shell(git:*)' --allow-tool=write --no-ask-user
cat summary.md >> "$GITHUB_STEP_SUMMARY" |
Beta Was this translation helpful? Give feedback.
-
|
The issue: GitHub Copilot CLI does NOT support authentication via COPILOT_GITHUB_TOKEN in CI/CD environments like GitHub Actions. The device flow (asking for a code) is the expected behavior because Copilot CLI requires interactive browser-based OAuth. Why it fails in Actions: · COPILOT_GITHUB_TOKEN environment variable is ignored in non-interactive terminals Official GitHub docs confirm: The token must be a fine-grained personal access token with "Copilot Requests" permission, but even then, it's designed for local CLI use, not for GitHub Actions workflows. Workaround (if you absolutely need this):
- name: Restore Copilot session cache
uses: actions/cache@v3
with:
path: ~/.config/github-copilot
key: copilot-session-${{ runner.os }}
Bottom line: Copilot CLI is designed for human interactive use, not for CI/CD automation. The behavior you're seeing is intentional, not a bug. Use the REST API instead if you need automation. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
🏷️ Discussion Type
Question
💬 Feature/Topic Area
Copilot CLI
Body
We cannot authenticate in GitHub Copilot CLI within an Actions workflow. Here is an example:
Even following the docs and instructions from GitHub, the workflow fails saying that no authentication was found, or asks for device authentication:
References
Any feedback would be much appreciated.
Beta Was this translation helpful? Give feedback.
All reactions