forked from jenkins-infra/contributor-spotlight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
117 lines (109 loc) · 3.28 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
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'
}
environment {
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
// 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'
}
post {
always {
recordIssues(tools: [checkStyle(id: 'typos', name: 'Typos', pattern: 'checkstyle.xml')])
}
}
}
stage('Install dependencies') {
environment {
NODE_ENV = 'development'
}
steps {
sh '''
asdf install
npm install
'''
}
}
stage('Build PR') {
when { changeRequest() }
environment {
NODE_ENV = 'development'
}
steps {
sh '''
npm run info
npm run build
'''
}
}
stage('Deploy PR to preview site') {
when {
allOf{
changeRequest target: 'main'
// Only deploy from infra.ci.jenkins.io
expression { infra.isInfra() }
}
}
environment {
NETLIFY_AUTH_TOKEN = credentials('netlify-auth-token')
}
steps {
sh 'netlify-deploy --draft=true --siteName "contributor-spotlight" --title "Preview deploy for ${CHANGE_ID}" --alias "deploy-preview-${CHANGE_ID}" -d ./public'
}
post {
success {
recordDeployment('jenkins-infra', 'contributor-spotlight', pullRequest.head, 'success', "https://deploy-preview-${CHANGE_ID}--contributor-spotlight.netlify.app")
}
failure {
recordDeployment('jenkins-infra', 'contributor-spotlight', pullRequest.head, 'failure', "https://deploy-preview-${CHANGE_ID}--contributor-spotlight.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_URL = 'https://jenkins-matomo.do.g4v.dev'
GATSBY_MATOMO_SITE_ID = '4'
}
steps {
script {
infra.withFileShareServicePrincipal([
servicePrincipalCredentialsId: 'contributors-jenkins-io-fileshare-service-principal-writer',
fileShare: 'contributors-jenkins-io',
fileShareStorageAccount: 'contributorsjenkinsio'
]) {
sh '''
npm run build
# Synchronize the File Share content
set +x
azcopy sync \
--skip-version-check \
--recursive=true \
--delete-destination=true \
./public/ "${FILESHARE_SIGNED_URL}"
'''
}
}
}
}
}
}