Skip to content

GHES: Auto-inject GH_HOST in agent container when GHES detected #1302

@lpcox

Description

@lpcox

Problem

When agentic workflows run on GHES, the gh CLI inside the agent container defaults to targeting github.com. Any gh commands (e.g., fetching repo data, creating PRs) fail with "Could not resolve to a Repository" errors.

Users must manually add a workflow step to extract the hostname from GITHUB_SERVER_URL and set GH_HOST via GITHUB_ENV.

Proposal

When GITHUB_SERVER_URL is not https://github.com (or engine.api-target is set):

  1. Automatically set GH_HOST in the agent container environment
  2. Extract hostname from GITHUB_SERVER_URL (strip https:// prefix)
  3. Inject early in the workflow via GITHUB_ENV so all subsequent steps pick it up

Workaround

We added this step manually to our lock file:

- name: Configure gh for GHE
  run: |
    SERVER_URL="${GITHUB_SERVER_URL}"
    GHE_HOST="${SERVER_URL#https://}"
    echo "GH_HOST=${GHE_HOST}" >> "$GITHUB_ENV"
  env:
    GITHUB_SERVER_URL: ${{ github.server_url }}

This should be built in.

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions