Skip to content

Commit

Permalink
fix: enable sonar with quality gate check as part of build (#54)
Browse files Browse the repository at this point in the history
* ci: add sonar scanner to pipeline

* ci: update sonar stage

* ci: add missing steps

* ci: call sonar scanner directly

* ci: ignore sonar folder

* ci: using jenkins plugin

* ci: set sonar home

* ci: trying sonarqube tool name

* ci: use versioned scanner

* ci: another try

* ci: next try

* ci: set in environment

* ci: use minor versioning

* ci: correct tool path

* ci: scan src files

* ci: change order of sonar scanner

* ci: remove sonar login from properties

* ci: sonar analysis after test to publish coverage tp sonar

* ci: generate lcov report for sonar

* ci: remove json test report

* ci: path for html report

* ci: passing cobertura report to sonar

* ci: revert to lcov paths

* ci: add quality gate keeper

* ci: change to 10 mins

* fix: prevent saving to dependencies

* ci: change prepare step

* ci: put to dev dependencies

* ci: redundant variable

* ci: reenable quality gate
  • Loading branch information
priynand authored and GitHub Enterprise committed Oct 8, 2021
1 parent 75f75a4 commit ae10580
Show file tree
Hide file tree
Showing 6 changed files with 2,287 additions and 2,182 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
.idea/
coverage/
.scannerwork/
45 changes: 29 additions & 16 deletions ci/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/groovy

// Node label
// Find more info about these:
// Build Agent Info:
// https://engit.cisco.com/build/cloudbees-jenkins/documentation-central-jenkins-build-agents
pipeline {
agent any
Expand All @@ -12,25 +11,18 @@ pipeline {
ansiColor('xterm')
}
environment {
GH_CRED = credentials('github_creds')
PATH="/usr/cisco/bin/:$PATH"
}

stages {
stage('Prerequisite Check') {
stage('Setup & Install Dependencies') {
steps {
sh 'node -v'
sh 'npm -v'
sh 'npm install yarn'
sh 'pwd'
sh 'git --version'
sh 'which git'
echo 'Install local Yarn'
sh 'npm install yarn -D'
echo " current workspace ${env.WORKSPACE}"
echo "PATH=$PATH"
}
}
stage('Install dependencies') {
steps {
echo 'Install dependencies (yarn install).'
sh './node_modules/yarn/bin/yarn install'
}
}
Expand All @@ -41,7 +33,7 @@ pipeline {
//@TODO: handle lint errors (fail build??)
}
}
stage('Run unit test') {
stage('Run Unit Test') {
steps {
sh './node_modules/yarn/bin/yarn test:coverage'
publishHTML([
Expand All @@ -60,12 +52,33 @@ pipeline {
sourceFileResolver: sourceFiles('NEVER_STORE')
}
}
stage('Build package') {
stage('SonarQube Analysis') {
environment {
scannerHome = tool 'sonar-scanner'
}
steps {
withSonarQubeEnv(credentialsId: 'sonar_login', installationName: 'BMS SonarQube') {
echo "PATH=$PATH"
sh 'env'
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
stage('Sonar GateKeeper') {
steps {
timeout(time: 10, unit: 'MINUTES') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
waitForQualityGate abortPipeline: true
}
}
}
stage('Build Package') {
steps {
sh './node_modules/yarn/bin/yarn build'
}
}
stage('Publish release') {
stage('Publish Release') {
steps {
script {
if (env.BRANCH_NAME == "master") {
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
testEnvironment: 'jsdom',
// Clear mocks in between tests by default
clearMocks: true,
coverageReporters: ['cobertura', 'clover', 'html', 'json', 'text'],
coverageReporters: ['cobertura', 'clover', 'html', 'lcov'],
};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"fix": "run-s fix:*",
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"fix:lint": "eslint src --ext .ts --fix",
"prepare": "run-s build && husky install",
"prepare": "husky install",
"release": "semantic-release",
"test": "run-s build test:*",
"test:lint": "eslint src --ext .ts",
Expand All @@ -83,8 +83,7 @@
},
"dependencies": {
"events": "^3.3.0",
"webrtc-adapter": "^8.0.0",
"yarn": "^1.22.15"
"webrtc-adapter": "^8.0.0"
},
"lint-staged": {
"*.ts": [
Expand Down
21 changes: 21 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# required properties
sonar.projectKey=webrtc-core
sonar.projectName=WebRTC Core

# host info
sonar.host.url=https://engci-sonar-sjc.cisco.com/sonar

# optional description
sonar.projectDescription=WebRTC Core library for CPaaS

# path to source directories (required)
sonar.sources=src

# exclusions
sonar.exclusions=

# coverage reporting
sonar.javascript.lcov.reportPaths=coverage/lcov.info

# Encoding of the source code
sonar.sourceEncoding=UTF-8
Loading

0 comments on commit ae10580

Please sign in to comment.