LoginSignup
48
18

More than 3 years have passed since last update.

Github Actions で secret を使う

Last updated at Posted at 2020-08-19

secret の登録

github の project の setting > secrets から登録する
https://github.com/$user/$project/settings/secrets

ここでは、 SECRET_HOGE という適当な secret を作った。

secret を環境変数に入れる

# .github/workflows/hello.yml

name: Hello
on: push
env:
  SECRET_HOGE_1: ${{secrets.SECRET_HOGE}} ## ※1
jobs:
  hello:
    runs-on: ubuntu-latest
    name: Hello
    steps:
      - name: Checkout
        uses: actions/checkout@master
      - name: run hello action
        env:
          SECRET_HOGE_2: ${{secrets.SECRET_HOGE}}  ## ※2
        uses: ./.github/actions/hello

下記の3ヶ所で設定できてスコープが違う

  • env
  • jobs.<job_id>.env
  • jobs.<job_id>.steps.env

action から使用

// .github/actions/hello/index.js
console.log("SECRET_HOGE_1 = ", process.env.SECRET_HOGE_1); 
console.log("SECRET_HOGE_2 = ", process.env.SECRET_HOGE_2);

githubの画面上のアウトプットは一応 *** とマスクされるけど、実際は出力しちゃだめ

Run ./.github/actions/hello

SECRET_HOGE_1 =  ***
SECRET_HOGE_2 =  ***
48
18
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
48
18