0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

"GITHUB_TOKEN" の名称を使いたいけどそれだとGitHub CLIが使えない→ "GH_TOKEN" を使うといいよ

Posted at

結論

gh auth token によって GitHub CLI 用の (gh auth login で生成された) トークンが取れる。
それを GH_TOKEN にセットしておけばOK

TOKEN=$(gh auth token)
export GH_TOKEN=$TOKEN

理由

GH_TOKEN, GITHUB_TOKEN (in order of precedence): an authentication token that will be used when a command targets either or a subdomain of . Setting this avoids being prompted to authenticate and takes precedence over previously stored credentials.
https://cli.github.com/manual/gh_help_environment

つまり GitHub CLI では、

  • gh auth login で生成されたトークンよりも GITHUB_TOKEN を優先するが、
  • GITHUB_TOKEN よりも GH_TOKEN をさらに優先する

ということ。

背景

関わるリポジトリが何らかの理由で GITHUB_TOKEN という名称の変数にPATを設定させてくる場合があると思う。(ないかも)
その場合に困ることとして、 GitHub CLI がそのリポジトリ内では使えなくなることが挙げられる。
どうにかして回避したいと思い調べたので一旦の解決策を備忘として書いた。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?