-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.one
123 lines (108 loc) · 3.69 KB
/
Jenkinsfile.one
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//import groovy.transform.CompileStatic
//@GrailsCompileStatic, @CompileStatic or @CompileDynamic CompileStatic
//@CompileStatic
/* Requires the Docker Pipeline plugin */
pipeline {
agent {
docker {
image 'node:20.16.0-alpine3.20'
args '--user=root -m 512m --cpus=1.5'
}
}
options {
ansiColor('xterm')
}
stages {
stage('demo') {
steps {
// Using xterm
ansiColor('xterm') {
echo "\033[31;1m Executing demo stage: \033[0m"
}
// Using vga
ansiColor('vga') {
echo "\033[31;1m command-1 \033[0m"
}
echo "\033[31;1m command-2 \033[0m"
}
}
stage('Clean') {
steps {
echo '\033[34mClean\033[0m \033[33mStage\033[0m \033[35mPipeline\033[0m'
sh 'npm cache clean --force'
}
}
stage('Build') {
steps {
echo '\033[34mBuild\033[0m \033[33mStage\033[0m \033[35mPipeline\033[0m'
sh 'node --version'
//sh 'npm install jest --loglevel=verbose'
sh 'npm install jest'
//sh 'npm install npm-groovy-lint --loglevel=verbose'
sh 'npm install npm-groovy-lint'
sh 'apk add openjdk17-jre'
}
}
stage('Groovy-lint Jenkinsfile') {
steps {
echo '\033[34mLint\033[0m \033[33mJenkinsfile\033[0m \033[35mPipeline\033[0m'
echo 'Lint..'
sh 'export PATH="/bin:./node_modules/.bin:$PATH"'
echo "PATH: $PATH"
echo "PWD: $PWD"
sh 'ls -latr'
sh 'ls -latr ./node_modules/.bin'
//sh './node_modules/.bin/npm-groovy-lint --verbose 1 --format --parse Jenkinsfile'
sh './node_modules/.bin/npm-groovy-lint --format --parse Jenkinsfile'
}
}
stage('Tests') {
steps {
echo '\033[34mTests\033[0m \033[33mStage\033[0m \033[35mPipeline\033[0m'
echo 'Testing..'
sh 'export PATH="/bin/:./node_modules/.bin/:$PATH"'
echo "PATH: $PATH"
sh 'ls -ltr ./node_modules/.bin'
//sh 'npm test'
sh 'node ./node_modules/jest/bin/jest.js'
//sh '~/.bin/jest test.sum.js'
//sh 'jest'
}
}
stage('Deploy') {
agent {
label 'Noeud-vm-lxc-other' // Nom de l'agent SSH configuré dans Jenkins
}
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps {
echo '\033[34mDeploy\033[0m \033[33mStage\033[0m \033[35mPipeline\033[0m'
/*
sshagent(['ssh-credentials-id']) {
sh '''
ssh -o StrictHostKeyChecking=no agent1_jenkins@remote-server 'mkdir -p ~/deploy'
scp -o StrictHostKeyChecking=no Jenkinsfile agent1_jenkins@192.168.3.84:~/deploy
ssh -o StrictHostKeyChecking=no agent1_jenkins@192.168.3.84 'echo 1 >file'
'''
}
*/
echo 'Success'
echo 'Deploying....'
}
}
}
post {
always {
echo 'Pipeline finished.'
}
success {
echo 'Pipeline succeeded!'
}
failure {
echo 'Pipeline failed!'
}
}
}