SonarQube Quality Gate fix
- Configure the Webhook in sonarqube

- Webhook url
http://<jenkins-url>:<port>/sonarqube-webhook

- Now navigate to jenkins -> Configure System -> SonarQube -> Advanced

- Now create a jenkinsfile as shown below
pipeline {
agent { label 'jdk11-mvn3.8.4' }
triggers {
cron('45 23 * * 1-5')
pollSCM('*/5 * * * *')
}
tools {
maven 'MVN_3.8.4'
}
stages {
stage('scm') {
steps {
git url: 'https://github.com/GitPracticeRepo/spring-petclinic.git', branch: 'main'
}
}
stage('build') {
steps {
withSonarQubeEnv(installationName: 'SONAR_9.2.1') {
sh "mvn clean package sonar:sonar"
}
}
}
stage("Quality Gate") {
steps {
timeout(time: 1, unit: 'HOURS') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
waitForQualityGate abortPipeline: true
}
}
}
}
}

Pushing artifacts to artifactory
- Using declarative pipelines Refer Here for official docs and Refer Here for the official docs of scripted
- Refer Here for the github repository with the project examples to work with artifactory
- Now we will be building the pipeline for our spring petclinic project based on the example Refer Here
- Refer Here for the jenkinsfile created by us to push the artifacts to artifactory server.

- To Download the jar/war/any file from artifactory
Stash and unstash example
- Stash and unstash steps in jenkins will help copying files or directories from one node to other
- Consider a scenario, where you are build a project after build is success you need to deploy on to the test server
- Here build server is a different and test server is a different node
- We can use stash to copy the file(s) from one node and paste to the nodes using unstash
pipeline {
agent { label 'jdk11-mvn3.8.4' }
triggers {
cron('45 23 * * 1-5')
pollSCM('*/5 * * * *')
}
tools {
maven 'MVN_3.8.4'
}
stages {
stage('scm') {
steps {
git url: 'https://github.com/GitPracticeRepo/spring-petclinic.git', branch: 'jfrog'
}
}
stage ('Artifactory configuration') {
steps {
rtMavenDeployer (
id: "MAVEN_DEPLOYER",
serverId: 'JFROG-OSS',
releaseRepo: 'qt-maven-releases',
snapshotRepo: 'qt-maven-snapshots'
)
}
}
stage ('Exec Maven') {
steps {
withCredentials([usernamePassword(credentialsId: 'JFROG_ARTIFACTORY', usernameVariable: 'ARTIFACTORY_USERNAME', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
rtMavenRun (
tool: 'MVN_3.8.4',
pom: 'pom.xml',
goals: 'clean install',
deployerId: "MAVEN_DEPLOYER"
)
stash includes: '**/*.jar', name: 'spcjar'
}
}
}
stage ('Publish build info') {
steps {
rtPublishBuildInfo (
serverId: 'JFROG-OSS'
)
}
}
stage ('copy to other node') {
agent { label 'MASTER'}
steps {
unstash 'spcjar'
}
}
}
}