HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
GitHub Action을 활용한 자동 크롤러 웹 페이지 만들기
/
📝
8. 환경변수
📝

8. 환경변수

환경변수는 구문 내에서 변수처럼 사용할 수 있는 값입니다. 아래 코드를 실행해보세요.
name: sub on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: 1. 변수출력 env: NAME: 'hojun.lee' run: echo "내 이름은 $NAME 입니다." - name: 2. 변수출력 env: ID: ${{ github.actor }} run: echo "내 이름은 $NAME, 내 아이디는 $ID 입니다."
 
정상적으로 실행이 되지 않죠? 해당 환경 변수는 전역변수는 아닙니다. 따라서 아래와 같이 구문을 수정해주도록 하겠습니다.
name: sub on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: 1. 변수출력 env: NAME: 'hojun.lee' AGE: 10 HUMAN: true ID: ${{ github.actor }} run: | echo "내 이름은 $NAME 입니다." echo "내 이름은 $NAME, 내 아이디는 $ID 입니다." echo "내 이름은 $NAME, 내 아이디는 $ID 입니다. 제 나이는 $AGE이고, 휴먼 : $HUMAN 입니다."
 
해당 문서는 아래 2개의 문서를 참고하고 있습니다.
Environment variables
GitHub sets default environment variables for each GitHub Actions workflow run. You can also set custom environment variables in your workflow file. GitHub Actions is available with GitHub Free, GitHub Pro, GitHub Free for organizations, GitHub Team, GitHub Enterprise Cloud, GitHub Enterprise Server, GitHub One, and GitHub AE.
https://docs.github.com/en/actions/reference/environment-variables
Context and expression syntax for GitHub Actions
You can use expressions to programmatically set variables in workflow files and access contexts. An expression can be any combination of literal values, references to a context, or functions. You can combine literals, context references, and functions using operators. Expressions are commonly used with the conditional if keyword in a workflow file to determine whether a step should run.
https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context
 
암호화된 환경변수를 사용하는 것도 가능합니다. API KEY 같은 것을 관리하실 때 사용할 수 있습니다. settings 탭에서 secret 탭에서 관리 가능하며, 접근 코드는 공식 문서를 참고하여 올려드립니다.
steps: - name: Hello world action with: # Set the secret as an input super_secret: ${{ secrets.SuperSecret }} env: # Or as an environment variable super_secret: ${{ secrets.SuperSecret }}
docs.github.com
https://docs.github.com/en/actions/reference/encrypted-secrets