-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create and Configure Jenkins job #144
Comments
Configure NodeJs Version on pipelinepipeline script 내부에서 특정 nodejs 버전을 사용하도록 정의하기 위해서는 NodeJs plguin을 설치해준다. Jenkins 관리 -> Global Tools Configuration 에서 사용할 NodeJs을 선택하여 등록한다. Pipeline Script
#!/usr/bin/env groovy
pipeline {
agent any
tools {
nodejs "nodejs12.13.0"
}
stages {
stage('Node') {
steps {
sh "which node"
sh "node --version"
}
}
}
}
node {
env.NODEJS_HOME = tool name: 'nodejs12.13.0'
env.PATH="${env.NODEJS_HOME}/bin:${env.PATH}"
stage ('Env') {
sh "which node"
sh "node --version"
}
} |
Generate Junit ReportInstallation jest-junit프로젝트에 jest-junit을 설치한다 yarn add --dev jest-junit Configure to generate report file
reporters: ['default', 'jest-junit'],
// or
reporters: [
'default',
[
'jest-junit',
{
outputDirectory: '<rootDir>/tests/coverages/reports',
outputName: 'test-junit-report.xml',
},
],
],
"jest-junit": {
"outputDirectory": "tests/coverages/reports",
"outputName": "test-junit-report.xml"
}, Configure jenkinsJUnit plugin을 설치한다. jenkins pipeline 스크립트에서 test 수행 결과를 전달하기 위해 다음과 같이 추가해준다. stage('Unit Test') {
steps {
sh "yarn run test:unit"
}
post {
always {
junit "tests/coverages/reports/test-junit-report.xml"
}
}
} 생성된 Report 확인젠킨스스의 해당 job의 메인 화면에서는 아래와 같은 테스트 결과 그래프를 확인할 수 있다. 각 build job 아이템에서는 아래와 같은 테스트 리포트 파일이 생성된다. 또한 각 PR에서는 다음과 같이 Checks와 빌드 상태에서 테스트 진행 상태 및 결과를 확인할 수 있다. |
Integration with SonarQube
SonarQube 프로젝트 생성젠킨스와 연동하고자 하는 소나큐브 프로젝트를 생성한다.
Configure JenkinsInstall SonarQube Scanner plugin젠킨스 "플러그인 관리"에서 SonarQube Scanner 플러그인을 설치한다. Add Credentail for sonarqubesonarqube token 정보를 jenkins credential에 등록한다. Configure SonarQube Server"<Jenkins 관리> → <시스템 설정> → " 항목에 연동할 sonarqube 설정을 등록한다. sonarqube scanner 설정"Global Toll Configuration" 에서 SonarQube Scanner 설정을 해준다. Jenkins pipeline 작성sonarqube로 분석 결과를 전송하기 위해서는 아래와 같이 2개의 stage가 등록이 되어야한다.
#!/usr/bin/env groovy
pipeline {
// ...SKIP
stages {
// ...SKIP
stage('SonarQube Analysis') {
environment {
scannerHome = tool 'SonarQubeScanner'
}
steps {
script{
withCredentials([string(credentialsId: 'JPT1046', variable: 'TOKEN')]) {
withSonarQubeEnv('SonarQubeServer') {
sh "${scannerHome}/bin/sonar-scanner \
-Dsonar.projectKey=th-bank-webapp \
-Dsonar.sources=./src \
${args} \
"
}
}
}
}
}
stage('SonarQube Quality Gate') {
steps {
script{
timeout(time: 10, unit: 'MINUTES') {
waitForQualityGate abortPipeline: false
}
}
}
}
}
} jest 및 lint 결과를 SonarQube로 전송하기jest 결과를 SonarQube로 전송하기jest 수행 결과를 sonarqube로 전송하기 위한 report를 생성하기 위해서는 해당 format으로 전환해주기 위해 jest-sonar 패키지를 설치해준다. yarn add -D jest-sonar jest 수행 시에 sonar report를 생성하도록 추가해준다. reporters: [
'default',
[
'jest-sonar',
{
outputDirectory: '<rootDir>/tests/coverages/reports',
outputName: 'test-sonar-report.xml',
reportedFilePath: 'absolute',
},
],
], Lint 결과를 SonarQube로 전송하기sonarqube로 전송하기 위한 lint report 파일 생성을 위해 CI pipeline의 lint stage에 다음과 같이 추가해준다. sh "yarn lint -- -f json -o eslint.json" |
The text was updated successfully, but these errors were encountered: