-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
107 lines (86 loc) · 2.9 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
pipeline {
agent any
stages {
stage('Git Checkout') {
steps {
// Check out the source code from a Git repository
git branch: 'main', url: 'https://github.com/nahidkishore/cicd-nexus-sonarqube-argocd.git'
}
}
stage('Unit Test') {
steps {
// Run unit tests using Maven
sh 'mvn test'
}
}
stage('Integrated Testing') {
steps {
// Run integrated tests using Maven, skipping unit tests
sh 'mvn verify -DskipUnitTests'
}
}
stage('Maven Build'){
steps{
sh 'mvn clean install'
}
}
stage('Static Code Analysis') {
environment {
SONAR_URL = "http://34.202.231.69:9000"
}
steps {
withCredentials([string(credentialsId: 'sonarqube', variable: 'SONAR_AUTH_TOKEN')]) {
sh 'mvn sonar:sonar -Dsonar.login=$SONAR_AUTH_TOKEN -Dsonar.host.url=${SONAR_URL}'
}
}
}
// nexus
stage('Upload Jar to Nexus'){
steps{
script{
def readPomVersion = readMavenPom file: 'pom.xml'
nexusArtifactUploader artifacts: [
[artifactId: 'springboot', classifier: '', file: 'target/Uber.jar', type: 'jar']
],
credentialsId: 'nexus-auth',
groupId: 'com.example',
nexusUrl: '54.83.103.209:8081', // Corrected URL
nexusVersion: 'nexus3',
protocol: 'http',
repository: 'demoapp-release',
version: "${readPomVersion.version}"
}
}
}
//
stage('Docker File Build and Test'){
steps {
sh 'docker build . -t cicd-nexus-sonarqube'
}
}
//
stage("Push to Docker Hub"){
steps{
echo 'login into docker hub and pushing image....'
withCredentials([usernamePassword(credentialsId: 'docker-cred', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]){
sh "docker tag cicd-nexus-sonarqube ${env.dockerHubUser}/cicd-nexus-sonarqube:latest"
sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword}"
sh "docker push ${env.dockerHubUser}/cicd-nexus-sonarqube:latest"
}
}
}
// stage('Push To Docker hub'){
// steps{
// script{
// withCredentials([string(credentialsId: 'docker-cred', variable: 'docker_hub_cred')]) {
// sh 'docker login -u nahid0002 -p ${docker_hub_cred}'
// sh 'docker image push nahid0002/$JOB_NAME:v1.$BUILD_ID '
// sh 'docker image push nahid0002/$JOB_NAME:latest '
// // some block
// }
// }
// }
// }
//
}
}