-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
97 lines (85 loc) · 3.04 KB
/
Jenkinsfile
File metadata and controls
97 lines (85 loc) · 3.04 KB
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
pipeline {
agent any
tools {
nodejs 'node'
}
environment {
KUBECONFIG = 'C:\\Users\\sindhu\\.kube\\config'
DOCKERHUB_REGISTRY = 'sindhusambasivam/hello_world'
DOCKERHUB_CREDENTIALS_ID = 'dockerhub'
}
stages {
stage('Install Dependencies') {
steps {
dir('C:\\Users\\sindhu\\CICD') {
script {
// Run npm install in the correct directory
bat 'npm install'
}
}
}
}
stage('Test') {
steps {
dir('C:\\Users\\sindhu\\CICD') {
script {
bat 'npm test'
}
}
}
}
stage('SonarQube Analysis') {
steps {
script {
// Download SonarScanner for Windows
bat "curl -o sonar-scanner.zip -L https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-windows.zip"
bat "powershell -Command Expand-Archive -Path sonar-scanner.zip -DestinationPath ."
// Set the scanner bin directory in the PATH
def scannerBinDir = "C:\\ProgramData\\Jenkins\\.jenkins\\tools\\jenkins.plugins.nodejs.tools.NodeJSInstallation\\sonar-scanner-5.0.1.3006-windows\\bin\\sonar-scanner.bat"
// Run SonarScanner
bat scannerBinDir
echo "SonarQube analysis complete"
}
}
}
stage('Build Docker image') {
steps {
dir('C:\\Users\\sindhu\\CICD') {
script {
bat "docker build -t ${DOCKERHUB_REGISTRY}:${BUILD_NUMBER} ."
}
}
}
}
stage('Push Docker image') {
steps {
script {
withEnv(['DOCKERHUB_USERNAME=sindhusambasivam', 'DOCKERHUB_PASSWORD=sindhu21*']) {
withCredentials([usernamePassword(
credentialsId: DOCKERHUB_CREDENTIALS_ID,
passwordVariable: 'DOCKERHUB_PASSWORD',
usernameVariable: 'DOCKERHUB_USERNAME'
)]) {
bat "docker login -u ${DOCKERHUB_USERNAME} -p ${DOCKERHUB_PASSWORD}"
bat "docker push ${DOCKERHUB_REGISTRY}:${BUILD_NUMBER}"
}
}
}
}
}
stage('Deploy to Kubernetes') {
steps {
script {
// Apply your Kubernetes Deployment and Service YAML files
bat 'kubectl apply -f node-web-app-deployment.yaml'
bat 'kubectl apply -f node-web-app-service.yaml'
}
}
}
}
post {
always {
bat 'docker logout'
}
}
}