forked from vdespa/learn-jenkins-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
164 lines (147 loc) · 5.31 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
pipeline {
agent any
environment {
NETLIFY_SITE_ID = 'e14b3b3e-a56d-4ae8-88f1-80bf103e9c69'
NETLIFY_AUTH_TOKEN = credentials('netlify-token')
REACT_APP_VERSION = "1.0.${BUILD_ID}"
}
stages {
stage('Build') {
agent {
docker {
image 'node:18-alpine'
reuseNode true
}
}
steps {
sh '''
ls -la
node --version
npm --version
npm ci
npm run build
ls -la
'''
}
}
stage('AWS') {
agent {
docker {
image 'amazon/aws-cli'
reuseNode true
args "--entrypoint=''"
}
}
environment {
AWS_S3_BUCKET = "learn-jenkins-202409162316"
}
steps {
withCredentials([usernamePassword(credentialsId: 'my-aws', passwordVariable: 'AWS_SECRET_ACCESS_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) {
sh '''
aws --version
echo "Hello S3" > index.html
aws s3 sync build s3://${AWS_S3_BUCKET}
'''
}
}
}
stage('Tests') {
parallel {
stage('Unit tests') {
agent {
docker {
image 'node:18-alpine'
reuseNode true
}
}
steps {
sh '''
#test -f build/index.html
npm test
'''
}
post {
always {
junit 'jest-results/junit.xml'
}
}
}
stage('E2E') {
agent {
docker {
image 'mcr.microsoft.com/playwright:v1.39.0-jammy'
reuseNode true
}
}
steps {
sh '''
npm install serve
node_modules/.bin/serve -s build &
sleep 10
npx playwright test --reporter=html
'''
}
post {
always {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'playwright-report', reportFiles: 'index.html', reportName: 'Local E2E', reportTitles: '', useWrapperFileDirectly: true])
}
}
}
}
}
stage('Deploy staging') {
agent {
docker {
image 'mcr.microsoft.com/playwright:v1.39.0-jammy'
reuseNode true
}
}
environment {
CI_ENVIRONMENT_URL = "${env.STAGING_URL}"
}
steps {
sh '''
npm install netlify-cli node-jq
node_modules/.bin/netlify --version
echo "Deploying to staging. Site ID: $NETLIFY_SITE_ID"
node_modules/.bin/netlify status
node_modules/.bin/netlify deploy --dir=build --json > deploy-output.json
CI_ENVIRONMENT_URL=$(node_modules/.bin/node-jq -r '.deploy_url' deploy-output.json)
npx playwright test --reporter=html
'''
}
post {
always {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'playwright-report', reportFiles: 'index.html', reportName: 'Staging E2E', reportTitles: '', useWrapperFileDirectly: true])
}
}
}
stage('Deploy prod') {
agent {
docker {
image 'mcr.microsoft.com/playwright:v1.39.0-jammy'
reuseNode true
}
}
environment {
CI_ENVIRONMENT_URL = 'https://beamish-peony-50bef2.netlify.app/'
}
steps {
sh '''
node --version
npm install netlify-cli
node_modules/.bin/netlify --version
echo "Deploying to production. Site ID: $NETLIFY_SITE_ID"
node_modules/.bin/netlify status
node_modules/.bin/netlify deploy --dir=build --prod
npx playwright test --reporter=html
'''
}
post {
always {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'playwright-report', reportFiles: 'index.html', reportName: 'Prod E2E', reportTitles: '', useWrapperFileDirectly: true])
}
}
}
}
}