-
TIL-2024.06.28 - Git Actions - 003. Multiple Jobs> DevOps/Git Actions 2024. 6. 29. 11:15
목표:
- 다중 Jobs에 대해 알아보자
- 작업을 병렬과 순차 실행하는 방법
다중 Jobs (+ 병렬):
> 다중 jobs 를 활용해 하나의 workflow 에서 여러 작업을 정의하고, 이를 병렬 혹은 순차적으로 실행가능 .
name: Test Project on: [push, workflow_dispatch] jobs: test: runs-on: ubuntu-latest # environment steps: # SECT: actions/checkout (리포지토리의 소스 코드를 워크플로우 실행 환경으로 체크아웃(다운로드)하는 기능) - name: Get code uses: actions/checkout@v3 # uses > action & run: run > shell script (command) # SECT: Install NODE - name: Install NodeJS uses: actions/setup-node@v3 with: # configuration (액션에 전달할 매개변수나 설정값을 지정할 때 사용됩니다. with 키워드 아래에 나열된 키-값 쌍은 해당 액션에 필요한 추가적인 설정을 제공) node-version: 18 # SECT: Install Dependencies - name: Install dependencies run: npm ci # SECT: Run Test - name: Run Tests run: npm test deploy: runs-on: ubuntu-latest steps: - name: Get code uses: actions/checkout@v3 - name: Install NodeJS uses: actions/setup-node@v3 with: node-version: 18 - name: Install dependencies run: npm ci - name: Build Project run: npm run build - name: Deploy run: echo "Deploying..."
- 기본적으로, 다중 jobs 을 설정하면, 작업들은 병렬 (Parallel) 적으로 실행된다.
- 다시말해, 다중 jobs 들이 동시에 도는 것을 의미.
다중 Jobs (+ 순차)
> needs 키워드를 사용하여, 작업 간의 의존성을 설정하여, 순차적으로 작업이 진행되게 할 수 있음
name: Test Project on: [push, workflow_dispatch] jobs: test: runs-on: ubuntu-latest # environment steps: # SECT: actions/checkout (리포지토리의 소스 코드를 워크플로우 실행 환경으로 체크아웃(다운로드)하는 기능) - name: Get code uses: actions/checkout@v3 # uses > action & run: run > shell script (command) ... 생략 ... deploy: needs: [test] # With "needs" pointing another job(identifying), you can run certain job after run first job. runs-on: ubuntu-latest ... 생략 ...
- 위의 코드와 같이 설정하면, 2번째 step인 deploy는 test 가 완료된 후에 작동.
- needs:[build, test] 와 같이 사용하면, 배열 안의 step 가 다 완료되어야 작동.
- 만약 선행 작업이 에러 등의 이유로 성공적으로 작동하지 못하면, deploy step 도 작동 하지 않음.
'> DevOps > Git Actions' 카테고리의 다른 글
TIL-2024.06.30 - Git Actions - 005. Activity Types & Filters , Workflow Skip (1) 2024.06.30 TIL-2024.06.29 - Git Actions - 004. Github Context Data (0) 2024.06.29 TIL-2024.06.23 - Git Actions - 002. Steps 가 호출하는 action (0) 2024.06.23 TIL-2024.06.22 - Git Actions - 001. WorkFlow (0) 2024.06.22 TIL-2024.06.21 - Git Actions - 000. Intro (0) 2024.06.21