Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pipeline {
- agent {
- label 'BUILD' //Executed on agents with this label
- }
- triggers {
- pollSCM('* * * * *') //Polls every minute. If your git repo supports web-hooks this is not necessary.
- }
- environment {
- NO_CHROME_OPTS = "TRUE" //Environment variables
- }
- options {
- disableConcurrentBuilds()
- }
- stages {
- stage('Checkout') {
- steps {
- checkout scm //Checks out the SCM where the Jenkinsfile is located
- addJFrogCredentialsToGradlePropertiesFile() //custom groovy method
- }
- }
- stage('Frontend Static Code Analysis') { //stages are displayed in Jenkins UI
- steps {
- sshagent(['git']) { //provide SSH key for a git repo from another project necessary for the build, "git" is configured in Jenkins
- script {
- try {
- sh './gradlew tslint --no-daemon'
- } finally { //make checkstyle results accessible to user
- checkstyle canComputeNew: false, defaultEncoding: '', healthy: '', pattern: 'frontend/tslint-result.xml', unHealthy: ''
- }
- }
- }
- }
- }
- stage('Frontend Unit Tests') {
- steps {
- sshagent(['git']) {
- script {
- try {
- sh './gradlew cleanFrontendTest --no-daemon'
- sh './gradlew frontendUnitTest --no-daemon'
- } finally {
- junit 'frontend/test/karma-result.xml' //make junit report accessible to user
- }
- }
- }
- }
- }
- stage('Unit & Integration Tests') {
- steps {
- script {
- try {
- sh './gradlew clean test --no-daemon'
- } finally {
- junit '**/build/test-results/test/*.xml'
- }
- }
- }
- }
- stage('End 2 End Tests') {
- steps {
- script {
- try {
- sh './gradlew e2e --no-daemon'
- } finally {
- junit '**/e2e-results/junit-formatted/*.xml'
- publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'frontend/test/e2e-results/html-formatted/', reportFiles: 'htmlReport.html', reportName: 'End 2 End Test Report', reportTitles: ''])
- } //make the HTML results of the e2e tests available to user
- }
- }
- }
- stage('Publish Artifact') {
- steps {
- sh './gradlew publish --no-daemon'
- }
- }
- stage('SonarQube Analysis') {
- steps {
- script {
- scannerHome = tool 'sonarscanner'
- }
- withSonarQubeEnv('sonar') {
- sh "${scannerHome}/bin/sonar-scanner"
- }
- }
- }
- }
- post {
- always { //If the build fails, send an email to the last person(s) to commit since the last green build
- step([$class : 'Mailer',
- notifyEveryUnstableBuild: true,
- recipients : [emailextrecipients([[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']])].join(' ')])
- }
- }
- }
- private void addJFrogCredentialsToGradlePropertiesFile() { //Write jFrog credentials to gradle.properties file
- withCredentials([usernamePassword(credentialsId: 'jFrog', usernameVariable: 'JFROG_USER', passwordVariable: 'JFROG_PASSWORD')]) {
- sh "rm -f ~/.gradle/gradle.properties"
- sh "echo jFrogUser=$JFROG_USER >> ~/.gradle/gradle.properties"
- sh "echo jFrogPassword=$JFROG_PASSWORD >> ~/.gradle/gradle.properties"
- }
- }
Add Comment
Please, Sign In to add comment