CI/CD 구축 - 5. Jest, Lint

송기영개발잘하고싶다·2023년 5월 12일
0

JENKINS

목록 보기
7/7

개요

React에서 많이 사용하는 단위 테스트를 해주는 Jest과 Lint를 Jenkins pipeline에 같이 넣는 방법을 설명하겠습니다.

사실 Jenkins에 Jest과 Lint를 추가하는 방법은 Jenkinsfile 수정하면되므로 굉장히 간단한 작업입니다.

  1. Jest를 설치하는 방법은 Jest를 설치해보자를 참고하시기 바랍니다.
  2. Airbnb Lint를 적용하는 방법은 Airbnb Lint 적용해보자를 참고하시기 바랍니다.

Jenkinsfile

CI/CD구축 시리즈 통합 파일의 내용입니다.

	pipeline {
    agent any
      tools {nodejs "16.14.0"}
        stages {
          stage("Build") {
            steps{
              sh "npm install"
              sh "npm run build"
            }
          }
          stage("sonarqube") {
            steps{
              script{
                def scannerHome = tool 'sonarqube-scanner';
                withSonarQubeEnv(credentialsId:"SONAR_TOKEN",installationName:'sonarqube') {
                  sh "${scannerHome}/bin/sonar-scanner"
                }
              }
            }
          }
          stage("Test") {
            steps {
              script{
                sh 'npm run test'
              }
            }
          }
          stage("Lint") {
            steps{
              script{
                FAILED_STAGE=env.STAGE_NAME
                sh "npm install"
                sh "npm run lint"
              }
            }
          }
        }
}

코드 푸쉬 후 확인

코드 푸쉬 후 Jest와 Lint가 정상적으로 실행됬는지 확인이 가능합니다.

레퍼런스
https://code00.tistory.com/137
https://code00.tistory.com/141

profile
업무하면서 쌓인 노하우를 정리하는 블로그🚀 풀스택 개발자를 지향하고 있습니다👻

0개의 댓글