LoginSignup
0
0

More than 1 year has passed since last update.

[備忘録]シークレット変数を使ってGitHub Actionsで機密情報を利用する

Last updated at Posted at 2023-04-02

はじめに

機密情報をGitHub Actionsで使う方法を調べてもなかなか出てこなくて手こずったので、今回行った方法を備忘録として記録しておきたい。

シークレット変数を設定してPythonファイルで利用する

Settingsでの操作

まず、GitHubの任意のレポジトリを開き、[Settings]→[Secrets and Variables]→[Actions]→[New repository secret]を選択する。
次に、NameとSecret(APIキーなどの機密情報)を入力して登録する。

ワークフローでの操作(ymlファイル)

- name: Run XXX
        env:
          API_KEY: ${{ secrets.API_KEY }} # secretsに登録した環境変数
        run:
          python/XXX.py #XXX.pyを実行

Pythonファイルでの操作

import os
# secretsに登録した環境変数の呼び出し
API_KEY = os.environ.get("API_KEY")
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