React에서 많이 사용하는 단위 테스트를 해주는 Jest과 Lint를 Jenkins pipeline에 같이 넣는 방법을 설명하겠습니다.
사실 Jenkins에 Jest과 Lint를 추가하는 방법은 Jenkinsfile 수정하면되므로 굉장히 간단한 작업입니다.
- Jest를 설치하는 방법은 Jest를 설치해보자를 참고하시기 바랍니다.
- Airbnb Lint를 적용하는 방법은 Airbnb Lint 적용해보자를 참고하시기 바랍니다.
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