Skip to content

Commit

Permalink
[JENKINS] - Add jest unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Nov 11, 2020
1 parent 857b4ab commit d8af5b7
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,64 @@ pipeline {
}
}

stage('Tests') {
steps {
parallel(

"Volto": {
node(label: 'docker') {
script {
try {
sh '''docker run -i --name="$BUILD_TAG-volto" -e NAMESPACE="$NAMESPACE" -e DEPENDENCIES="$DEPENDENCIES" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/volto-test'''
sh '''mkdir -p xunit-reports/coverage'''
sh '''docker cp -r $BUILD_TAG-volto:/opt/frontend/my-volto-project/coverage/* xunit-reports/coverage/'''
sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/junit.xml xunit-reports/'''
sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/unit_tests_log.txt xunit-reports/'''
stash name: "xunit-reports", includes: "xunit-reports/*"
junit 'xunit-reports/junit.xml'
archiveArtifacts artifacts: 'xunit-reports/unit_tests_log.txt', fingerprint: true
publishHTML (target : [
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'xunit-reports/coverage/lcov-report',
reportFiles: 'index.html',
reportName: 'UTCoverage',
reportTitles: 'Unit Tests Code Coverage'
])
} finally {
sh '''docker rm -v $BUILD_TAG-volto'''
}
}
}
}
)
}
}

stage('Report to SonarQube') {
// Exclude Pull-Requests
when {
allOf {
environment name: 'CHANGE_ID', value: ''
}
}
steps {
node(label: 'swarm') {
script{
checkout scm
dir("xunit-reports") {
unstash "xunit-reports"
}
withSonarQubeEnv('Sonarqube') {
sh '''sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER'''
sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done'''
}
}
}
}
}

}

post {
Expand Down

0 comments on commit d8af5b7

Please sign in to comment.