{"record":{"id":"73c3e897c5c18299","repo":"MahApps/MahApps.Metro","slug":"the-github-token-environment-variable-is-not-defin","errorCode":null,"errorMessage":"The GITHUB_TOKEN environment variable is not defined.","messagePattern":"The GITHUB_TOKEN environment variable is not defined\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"build.cake","lineNumber":330,"sourceCode":"    .Description(\"Ensures XAML Formatting is Clean\")\n    .Does(() =>\n{\n    Func<IFileSystemInfo, bool> exclude_Dir =\n        fileSystemInfo => !fileSystemInfo.Path.Segments.Contains(\"obj\") && !fileSystemInfo.Path.ToString().Contains(\"Styles/Themes\");\n\n    var files = GetFiles(srcDir + \"/**/*.xaml\", new GlobberSettings { Predicate = exclude_Dir });\n    Information(\"\\nChecking \" + files.Count() + \" file(s) for XAML Structure\");\n    ExecuteProcess(styler, \"-f \\\"\" + string.Join(\",\", files.Select(f => f.ToString())) + \"\\\" -c \\\"\" + stylerFile + \"\\\"\");\n});\n\nTask(\"CreateRelease\")\n    .WithCriteria<BuildData>((context, data) => !data.IsPullRequest)\n    .Does<BuildData>(data =>\n{\n    var token = EnvironmentVariable(\"GITHUB_TOKEN\");\n    if (string.IsNullOrEmpty(token))\n    {\n        throw new Exception(\"The GITHUB_TOKEN environment variable is not defined.\");\n    }\n\n    GitReleaseManagerCreate(token, \"MahApps\", repoName, new GitReleaseManagerCreateSettings {\n        Milestone         = data.GitVersion.MajorMinorPatch,\n        Name              = data.GitVersion.AssemblySemFileVer,\n        Prerelease        = data.IsPrerelease,\n        TargetCommitish   = data.GitVersion.BranchName,\n        WorkingDirectory  = \".\"\n    });\n});\n\n///////////////////////////////////////////////////////////////////////////////\n// HELPER\n///////////////////////////////////////////////////////////////////////////////\n\nvoid SignFiles(IEnumerable<FilePath> files, string description)\n{\n    var vurl = EnvironmentVariable(\"azure-key-vault-url\");","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/build.cake#L312-L348","documentation":"The Cake 'CreateRelease' task needs a GitHub access token to call GitReleaseManagerCreate and publish a release to the MahApps repo. It reads GITHUB_TOKEN from the environment and throws a plain Exception when the variable is empty or unset. The task is gated by !data.IsPullRequest, so it only runs on non-PR (push/release) builds.","triggerScenarios":"The 'CreateRelease' target executes (local or CI, not a PR build) and EnvironmentVariable(\"GITHUB_TOKEN\") returns null or empty. GitReleaseManagerCreate is never reached because the guard throws first.","commonSituations":"CI secret not configured (e.g. GITHUB_TOKEN missing from GitHub Actions secrets or AppVeyor environment). Running build.ps1 -Target CreateRelease locally without setting GITHUB_TOKEN in the shell. Token secret renamed or scoped away from the build job.","solutions":["Set the GITHUB_TOKEN environment variable before invoking Cake: in PowerShell use $env:GITHUB_TOKEN = '<token>'; in GitHub Actions use the automatic GITHUB_TOKEN secret (secrets.GITHUB_TOKEN) passed via env:.","Verify the CI job that runs CreateRelease actually has the secret in its environment (not just at workflow level).","If you are testing locally and don't need a release, run a different target (e.g. Default) instead of CreateRelease.","For GitHub Actions, map the built-in token explicitly: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}."],"exampleFix":"# before (PowerShell, token missing)\n./build.ps1 -Target CreateRelease\n# after\n$env:GITHUB_TOKEN = '<your PAT or CI token>'\n./build.ps1 -Target CreateRelease\n\n# GitHub Actions\nenv:\n  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}","handlingStrategy":"validation","validationCode":"// Before CreateRelease, validate the token and fail with a clear message\nvar token = EnvironmentVariable(\"GITHUB_TOKEN\");\nif (string.IsNullOrEmpty(token)) {\n    Warning(\"GITHUB_TOKEN not set — skipping CreateRelease.\");\n    return; // or: throw with remediation hint\n}\nGitReleaseManagerCreate(token, \"MahApps\", repoName, new GitReleaseManagerCreateSettings { /* ... */ });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure GITHUB_TOKEN as a secret in the CI environment for the release job, not just the workflow.","For GitHub Actions, map the built-in token: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}.","Run CreateRelease only from release/push pipelines; skip it for local/feature builds.","Document required environment variables (GITHUB_TOKEN, azure-key-vault-*) in the build README."],"tags":["build","cake","ci","github","environment","release"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}