-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
62 lines (60 loc) · 1.78 KB
/
Jenkinsfile
File metadata and controls
62 lines (60 loc) · 1.78 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
pipeline {
agent any
tools {
nodejs 'Node20' // Use the name from step 2
}
stages {
stage('Check Version') {
steps {
// Verify Node and NPM are available
sh 'node -v'
sh 'npm -v'
}
}
stage('Install Dependencies') {
steps {
// Install your project dependencies
sh 'npm install'
}
}
stage('Test') {
steps {
// Run your application tests
sh 'npm test'
}
}
stage('Build') {
steps {
// Build your application (e.g., for React/Vue)
sh 'npm run build'
}
}
stage ('Build image') {
steps {
sh 'docker build -t my-node-app:1.0 .'
}
}
stage('Docker Login') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASSWORD')]) {
sh 'docker login -u $DOCKER_USER -p $DOCKER_PASSWORD'
sh 'docker tag my-node-app:1.0 richdevops/my-node-app:1.0'
sh 'docker push richdevops/my-node-app:1.0'
sh 'docker logout'
}
}
}
stage('Push Docker Image') {
steps {
sh 'docker push richdevops/my-node-app:1.0'
sh 'docker logout'
}
}
stage('Deploy to Kubernetes') {
steps {
sh 'kubectl apply -f deployment.yaml --validate=false'
sh 'kubectl apply -f service.yaml'
}
}
}
}