forked from jenkins-infra/plugin-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
140 lines (130 loc) · 4.34 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
pipeline {
options {
timeout(time: 60, unit: 'MINUTES')
ansiColor('xterm')
disableConcurrentBuilds(abortPrevious: true)
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '5', numToKeepStr: '5')
}
agent {
label 'node'
}
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
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('Deploy to production') {
when {
allOf{
expression { env.BRANCH_IS_PRIMARY }
// Only deploy from infra.ci.jenkins.io
expression { infra.isInfra() }
}
}
environment {
NODE_ENV = 'production'
GATSBY_MATOMO_SITE_ID = '1'
GATSBY_MATOMO_SITE_URL = 'https://jenkins-matomo.do.g4v.dev'
// TODO: Remove this "custom PATH" once https://github.com/jenkins-infra/docker-builder/blob/e5749f5cf0392549a89ba3a5b41a41fe55ec48dd/Dockerfile#L46 is updated to persist it
PATH = "/home/jenkins/.local/bin:${env.PATH}"
}
steps {
withCredentials([
string(credentialsId: 'algolia-plugins-app-id', variable: 'GATSBY_ALGOLIA_APP_ID'),
string(credentialsId: 'algolia-plugins-search-key', variable: 'GATSBY_ALGOLIA_SEARCH_KEY'),
string(credentialsId: 'algolia-plugins-write-key', variable: 'GATSBY_ALGOLIA_WRITE_KEY'),
string(credentialsId: 'PLUGINSITE_STORAGEACCOUNTKEY', variable: 'PLUGINSITE_STORAGEACCOUNTKEY')
]) {
sh '''
yarn build
blobxfer upload \
--local-path ./plugins/plugin-site/public \
--storage-account-key $PLUGINSITE_STORAGEACCOUNTKEY \
--storage-account prodpluginsite \
--remote-path pluginsite \
--recursive \
--mode file \
--skip-on-md5-match \
--file-md5 \
--connect-timeout 30 \
--delete
'''
}
}
}
}
}