Skip to content

Commit 39e5cd3

Browse files
authored
Update pipeline
1 parent ae5f64b commit 39e5cd3

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

pipeline

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
pipeline {
22
agent any
33
environment {
4-
SCANNER_HOME = tool 'sonar-scanner' // Ensure 'sonar-scanner' tool is correctly configured in Jenkins
4+
SCANNER_HOME = tool 'sonar-scanner' // SonarQube scanner tool configuration
55
}
6-
76
options {
8-
skipStagesAfterUnstable() // Skip subsequent stages if a stage is unstable
9-
timestamps() // Add timestamps to pipeline logs for better debugging
7+
skipStagesAfterUnstable() // Skip remaining stages if one fails
8+
timestamps() // Add timestamps to logs
9+
disableConcurrentBuilds() // Avoid conflicts in builds
1010
}
1111

1212
stages {
1313
stage('Checkout Source Code') {
1414
steps {
15-
// Ensure a full clone to avoid shallow clone issues
1615
checkout([
17-
$class: 'GitSCM',
16+
$class: 'GitSCM',
1817
branches: [[name: '*/main']],
1918
userRemoteConfigs: [[url: 'https://github.com/Yaqoob599/java-example.git']],
2019
extensions: [[$class: 'CloneOption', noTags: false, shallow: false]]
@@ -24,14 +23,14 @@ pipeline {
2423

2524
stage('Test') {
2625
steps {
27-
sh "mvn clean test" // Clean before test to avoid stale outputs
26+
sh "mvn clean test" // Clean before testing
2827
}
2928
}
3029

3130
stage('SonarQube Analysis') {
3231
steps {
3332
withSonarQubeEnv('sonar-scanner') {
34-
sh '''
33+
sh '''
3534
$SCANNER_HOME/bin/sonar-scanner \
3635
-Dsonar.projectName=Java-app \
3736
-Dsonar.projectKey=Java-app \
@@ -45,14 +44,14 @@ pipeline {
4544
}
4645

4746
post {
48-
always {
49-
echo "Pipeline completed"
50-
}
5147
success {
52-
echo "Build and analysis completed successfully"
48+
echo "Pipeline completed successfully."
5349
}
5450
failure {
55-
echo "Pipeline failed"
51+
echo "Pipeline failed. Please check the logs for details."
52+
}
53+
always {
54+
cleanWs() // Clean workspace to avoid stale data
5655
}
5756
}
5857
}

0 commit comments

Comments
 (0)