forked from jenkins-infra/plugin-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile_k8s
171 lines (161 loc) · 4.33 KB
/
Jenkinsfile_k8s
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
165
166
167
168
169
170
171
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: "v1"
kind: "Pod"
metadata:
labels:
jenkins: "agent"
job: "plugin-site"
spec:
tolerations:
- key: "os"
operator: "Equal"
value: "linux"
effect: "NoSchedule"
- key: "jenkins"
operator: "Equal"
value: "infra.ci.jenkins.io"
effect: "NoSchedule"
- key: "kubernetes.azure.com/scalesetpriority"
operator: "Equal"
value: "spot"
effect: "NoSchedule"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
restartPolicy: "Never"
automountServiceAccountToken: false
containers:
- name: "jnlp"
image: "jenkinsciinfra/builder:2.2.65@sha256:2dfc744aa105675cfb06ddd5d46f399badb17ee813ed5d7bb4723ed36d9f7c3e"
resources:
limits: {}
requests:
memory: "4Gi"
cpu: "2"
'''
}
}
environment {
TZ = "UTC"
GET_CONTENT = "true"
NODE_ENV = "production"
}
triggers {
cron("${env.BRANCH_NAME == 'master' ? 'H H/3 * * *' : ''}")
}
options {
timeout(time: 60, unit: 'MINUTES')
ansiColor('xterm')
disableConcurrentBuilds(abortPrevious: true)
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '5', numToKeepStr: '5')
retry(3)
}
stages {
stage('Install Dependencies') {
steps {
sh 'asdf install'
sh 'NODE_ENV=development yarn install'
}
}
stage('Build PR') {
when {
not {
branch "master"
}
}
environment {
DISABLE_SEARCH_ENGINE = "true"
GATSBY_ALGOLIA_APP_ID = credentials('algolia-plugins-app-id')
GATSBY_ALGOLIA_SEARCH_KEY = credentials('algolia-plugins-search-key')
NETLIFY = "true"
}
steps {
sh 'yarn build'
}
}
stage('Build Production') {
when {
branch "master"
}
environment {
GATSBY_MATOMO_SITE_ID = "1"
GATSBY_MATOMO_SITE_URL = "https://jenkins-matomo.do.g4v.dev"
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')
}
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 azure') {
when {
branch "master"
}
environment {
PLUGINSITE_STORAGEACCOUNTKEY = credentials('PLUGINSITE_STORAGEACCOUNTKEY')
}
steps {
sh('''
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
''')
}
}
stage('Deploy to preview site') {
when {
changeRequest target: 'master'
}
environment {
NETLIFY_AUTH_TOKEN = credentials('netlify-auth-token')
}
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")
}
}
steps {
sh('/usr/local/bin/netlify-deploy --siteName "jenkins-plugin-site-pr" --title "Preview deploy for ${CHANGE_ID}" --alias "deploy-preview-${CHANGE_ID}" -d ./plugins/plugin-site/public')
}
}
}
}