Skip to content

Commit ae5f64b

Browse files
authored
Create pipeline
1 parent 42ef93c commit ae5f64b

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

pipeline

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
pipeline {
2+
agent any
3+
environment {
4+
SCANNER_HOME = tool 'sonar-scanner' // Ensure 'sonar-scanner' tool is correctly configured in Jenkins
5+
}
6+
7+
options {
8+
skipStagesAfterUnstable() // Skip subsequent stages if a stage is unstable
9+
timestamps() // Add timestamps to pipeline logs for better debugging
10+
}
11+
12+
stages {
13+
stage('Checkout Source Code') {
14+
steps {
15+
// Ensure a full clone to avoid shallow clone issues
16+
checkout([
17+
$class: 'GitSCM',
18+
branches: [[name: '*/main']],
19+
userRemoteConfigs: [[url: 'https://github.com/Yaqoob599/java-example.git']],
20+
extensions: [[$class: 'CloneOption', noTags: false, shallow: false]]
21+
])
22+
}
23+
}
24+
25+
stage('Test') {
26+
steps {
27+
sh "mvn clean test" // Clean before test to avoid stale outputs
28+
}
29+
}
30+
31+
stage('SonarQube Analysis') {
32+
steps {
33+
withSonarQubeEnv('sonar-scanner') {
34+
sh '''
35+
$SCANNER_HOME/bin/sonar-scanner \
36+
-Dsonar.projectName=Java-app \
37+
-Dsonar.projectKey=Java-app \
38+
-Dsonar.scm.provider=git \
39+
-Dsonar.java.binaries=target/classes \
40+
-Dsonar.verbose=true
41+
'''
42+
}
43+
}
44+
}
45+
}
46+
47+
post {
48+
always {
49+
echo "Pipeline completed"
50+
}
51+
success {
52+
echo "Build and analysis completed successfully"
53+
}
54+
failure {
55+
echo "Pipeline failed"
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)