-
Notifications
You must be signed in to change notification settings - Fork 69
/
Jenkinsfile
164 lines (152 loc) · 4.75 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 {
options {
timeout(time: 60, unit: 'MINUTES')
ansiColor('xterm')
disableConcurrentBuilds(abortPrevious: true)
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '5', numToKeepStr: '5')
}
agent {
label 'linux-arm64-docker || arm64linux'
}
triggers {
cron("${env.BRANCH_IS_PRIMARY ? 'H H/3 * * *' : ''}")
}
environment {
GET_CONTENT = 'true'
TZ = 'UTC'
// Amount of available vCPUs, to avoid OOM - https://www.gatsbyjs.com/docs/how-to/performance/resolving-out-of-memory-issues/#try-reducing-the-number-of-cores
// and 'The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph' error
// https://github.com/jenkins-infra/jenkins-infra/tree/production/hieradata/clients/controller.ci.jenkins.io.yaml#L327
GATSBY_CPU_COUNT = '4'
}
stages {
stage('Check for typos') {
steps {
sh 'typos --format json | typos-checkstyle - > checkstyle.xml || true'
recordIssues(tools: [checkStyle(id: 'typos', name: 'Typos', pattern: 'checkstyle.xml')], qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]])
}
}
stage('Install dependencies') {
environment {
NODE_ENV = 'development'
}
steps {
sh '''
asdf install
npm install --global yarn
yarn install
'''
}
}
stage('Build') {
environment {
DISABLE_SEARCH_ENGINE = 'true'
NODE_ENV = 'development'
}
steps {
sh('yarn build')
}
}
stage('Check build') {
when { expression { return !fileExists('./plugins/plugin-site/public/index.html') } }
steps {
error('Something went wrong, index.html was not generated')
}
}
stage('Lint and Test') {
environment {
NODE_ENV = 'development'
NODE_OPTIONS = '--experimental-vm-modules'
}
steps {
sh '''
yarn lint
yarn test
'''
}
}
stage('Deploy to preview site') {
when {
allOf {
changeRequest()
// Only deploy from infra.ci.jenkins.io
expression { infra.isInfra() }
}
}
environment {
NETLIFY_AUTH_TOKEN = credentials('netlify-auth-token')
}
steps {
sh('netlify-deploy --siteName "jenkins-plugin-site-pr" --title "Preview deploy for ${CHANGE_ID}" --alias "deploy-preview-${CHANGE_ID}" -d ./plugins/plugin-site/public')
}
post {
success {
recordDeployment('jenkins-infra', 'plugin-site', pullRequest.head, 'success', "https://deploy-preview-${CHANGE_ID}--jenkins-plugin-site-pr.netlify.app")
}
failure {
recordDeployment('jenkins-infra', 'plugin-site', pullRequest.head, 'failure', "https://deploy-preview-${CHANGE_ID}--jenkins-plugin-site-pr.netlify.app")
}
}
}
stage('Build production') {
when {
allOf{
expression { env.BRANCH_IS_PRIMARY }
expression { infra.isInfra() }
}
}
environment {
NODE_ENV = 'production'
GATSBY_ALGOLIA_APP_ID = credentials('algolia-plugins-app-id')
GATSBY_ALGOLIA_SEARCH_KEY = credentials('algolia-plugins-search-key')
GATSBY_ALGOLIA_WRITE_KEY = credentials('algolia-plugins-write-key')
GATSBY_MATOMO_SITE_ID = '1'
GATSBY_MATOMO_SITE_URL = 'https://jenkins-matomo.do.g4v.dev'
}
steps {
sh 'yarn build'
}
}
stage('Deploy to production') {
when {
allOf{
expression { env.BRANCH_IS_PRIMARY }
// Only deploy from infra.ci.jenkins.io
expression { infra.isInfra() }
}
}
steps {
script {
infra.withFileShareServicePrincipal([
servicePrincipalCredentialsId: 'infraci-pluginsjenkinsio-fileshare-service-principal-writer',
fileShare: 'plugins-jenkins-io',
fileShareStorageAccount: 'pluginsjenkinsio'
]) {
sh '''
# Don't output sensitive information
set +x
# Synchronize the File Share content
azcopy sync \
--skip-version-check \
--recursive=true\
--delete-destination=true \
--compare-hash=MD5 \
--put-md5 \
--local-hash-storage-mode=HiddenFiles \
./plugins/plugin-site/public/ "${FILESHARE_SIGNED_URL}"
'''
}
}
}
post {
failure {
// Retrieve azcopy logs and archive them when deployment fails
sh '''
cat /home/jenkins/.azcopy/*.log > azcopy.log
'''
archiveArtifacts 'azcopy.log'
}
}
}
}
}