Repository navigation
Expand file tree
/
Copy pathjenkinsfile
More file actions
94 lines (84 loc) · 2.37 KB
/
Copy pathjenkinsfile
File metadata and controls
94 lines (84 loc) · 2.37 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
pipeline {
agent any
tools {
nodejs 'NodeJS 21.4.0'
}
environment {
GITHUB_TOKEN = credentials('github-token')
}
stages {
//list current file path and directory
stage('List current directory') {
steps {
sh 'pwd'
sh 'ls -la'
}
}
stage('Set up Node.js') {
steps {
nodejs(nodeJSInstallationName: 'NodeJS 21.4.0') {
sh 'node --version'
sh 'npm --version'
}
}
}
stage('Checkout main branch') {
steps {
sh '''
git status
git checkout main
git pull
'''
}
}
stage('Install dependencies') {
steps {
sh 'npm install'
}
}
stage('Check code practices with ESLint') {
steps {
sh 'npm run lint'
}
}
stage('Format code with Prettier') {
steps {
sh 'npm run format'
}
}
stage('Remove console.log statements') {
steps {
sh 'find . -name "node_modules" -prune -o -name "*.js" -exec sed -i \'/console\\.log(/d\' {} \\;'
}
}
stage('Commit changes') {
steps {
withCredentials([string(credentialsId: 'github-token', variable: 'GITHUB_TOKEN')]) {
sh '''
git config --global user.email "shahaayush349@gmail.com"
git config --global user.name "Shah-Aayush"
git add .
git diff-index --quiet HEAD || git commit -m "Jetkins CI: perform integration steps"
git remote set-url origin https://$GITHUB_TOKEN:@github.com/Marwizz/react-ci-cd-demo.git
git push origin main
'''
}
}
}
stage('Run tests') {
steps {
sh 'npm test'
}
}
stage('Build app') {
steps {
sh 'npm run build'
}
}
stage('Clean up') {
steps {
sh 'rm -rf build'
}
}
}
}