ElectronNET/Electron.NET · error · BuildAbortedException

Could not resolve GitHub token.

Error message

Could not resolve GitHub token.

What it means

A GitHub target in the Nuke build (creating a release / uploading assets) needs a GitHub token to authenticate Octokit (new Credentials(gitHubToken) is constructed right after this check). It falls back to the GITHUB_TOKEN environment variable and throws BuildAbortedException if the token is null or empty, refusing to make unauthenticated GitHub API calls.

Solutions

  1. Export GITHUB_TOKEN with a valid personal access token (repo scope) before running the build, or
  2. In the CI workflow, wire the automatic token: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} on the build step.
  3. Check that any custom token source the target reads from (e.g. a parameter before the env fallback) actually provides a non-empty value.
  4. Ensure the token has sufficient permissions (contents:write) if the error recurs after authentication.

Example fix

// before (GitHub Actions step)
- run: ./build.sh Release
// after
- run: ./build.sh Release
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("GITHUB_TOKEN")))
    throw new InvalidOperationException("GITHUB_TOKEN must be set (CI: ${{ secrets.GITHUB_TOKEN }}).");

Try / catch

try
{
    // github release target
}
catch (BuildAbortedException ex) when (ex.Message.Contains("GitHub token"))
{
    Logger.Warn("No GITHUB_TOKEN available; skipping GitHub release step.");
}

Prevention

When it happens

Trigger: Executing the GitHub release/publish target (Build.cs:185) when GITHUB_TOKEN is not set (or empty), including when the preceding code path that sets gitHubToken did not run or yielded nothing.

Common situations: GitHub Actions workflow does not pass the built-in GITHUB_TOKEN to the build step (missing `env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}`); running the release target locally without a personal access token; token secret renamed or scoped to the wrong repo; using a fork where secrets are not available.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of ElectronNET/Electron.NET@87cc6f98b6 (2026-09-14). Data as JSON: /api/errors/1472f5250e5a8478. Report an issue: GitHub.

Appendix: source

Thrown at nuke/Build.cs:185

    Target PublishPreRelease => _ => _
        .DependsOn(PublishPackages)
        .Executes(() =>
        {
            string gitHubToken;

            if (GitHubActions != null)
            {
                gitHubToken = GitHubActions.Token;
            }
            else
            {
                gitHubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
            }

            if (gitHubToken.IsNullOrEmpty())
            {
                throw new BuildAbortedException("Could not resolve GitHub token.");
            }

            var credentials = new Credentials(gitHubToken);

            GitHubTasks.GitHubClient = new GitHubClient(
                new ProductHeaderValue(nameof(NukeBuild)),
                new InMemoryCredentialStore(credentials));

            GitHubTasks.GitHubClient.Repository.Release
                .Create("ElectronNET", "Electron.NET", new NewRelease(Version + VersionPostFix)
                {
                    Name = "ElectronNET.Core " + Version + VersionPostFix,
                    Body = String.Join(Environment.NewLine, LatestReleaseNotes.Notes),
                    Prerelease = true,
                    TargetCommitish = "develop",
                });
        });

View on GitHub (pinned to 87cc6f98b6)