-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile
More file actions
118 lines (111 loc) · 4.13 KB
/
Jenkinsfile
File metadata and controls
118 lines (111 loc) · 4.13 KB
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
pipeline {
agent { label 'site-agent' }
environment {
DOCKER_IMAGE_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
DOCKER_IMAGE_TAG_LATEST = "${env.BRANCH_NAME}-latest"
}
stages {
stage('Install npm dependencies') {
steps {
dir('frontend-next-migration'){
cache(defaultBranch: 'dev',
maxCacheSize: 2048,
caches: [
arbitraryFileCache(
path: "node_modules",
includes: "**/*",
cacheValidityDecidingFile: "package-lock.json"
)
]) {
sh "npm install"
}
}
}
}
// stage('Run automation tests') {
// steps {
// dir('frontend-next-migration') {
// withCredentials([file(credentialsId: 'alt-site-env-test-file', variable: 'ENV_LOCAL_FILE')]) {
// sh 'rm -f .env.local || true'
// sh 'cp $ENV_LOCAL_FILE .env.local'
// script {
// def firstTestResult = sh(script: 'npm run test:ci', returnStatus: true)
//
// if (firstTestResult != 0) {
// def retryResult = sh(script: 'npm run test:ci-retry-failed', returnStatus: true)
//
// if (retryResult != 0) {
// error("Tests failed after retry")
// }
// }
// }
// }
// }
// }
// post {
// always {
// dir('frontend-next-migration') {
// sh 'rm -f .env.local || true'
// recordCoverage(tools: [[parser: 'COBERTURA', pattern: 'coverage/cobertura-coverage.xml']])
// junit allowEmptyResults: true, checksName: 'Unit Tests', stdioRetention: 'FAILED', testResults: 'junit.xml'
// }
// }
// }
// }
stage('Build and Push Docker Image') {
agent { label 'docker-agent' }
when {
anyOf {
branch 'main'
branch 'dev'
}
}
steps {
dir('frontend-next-migration'){
withCredentials([
string(credentialsId: 'alt-docker-image-name-prefix', variable: 'IMAGE_NAME_PREFIX'),
file(credentialsId: 'alt-site-env-build-file', variable: 'ENV_LOCAL_FILE')
]) {
sh 'rm -f .env.local || true'
sh 'cp $ENV_LOCAL_FILE .env.local'
script {
def image = docker.build("${IMAGE_NAME_PREFIX}-site:${DOCKER_IMAGE_TAG}")
docker.withRegistry('https://index.docker.io/v1/', 'alt-dockerhub') {
image.push()
image.push("${DOCKER_IMAGE_TAG_LATEST}")
}
}
}
}
}
}
stage('Notify server') {
when {
anyOf {
branch 'main'
branch 'dev'
}
}
steps {
withCredentials([
string(credentialsId: 'alt-server-webhook-secret', variable: 'WEBHOOK_SECRET'),
string(credentialsId: 'alt-server-webhook-url', variable: 'WEBHOOK_URL')
]) {
script {
def payload = """{"name": "site", "tag": "${env.BRANCH_NAME}"}"""
withEnv(["PAYLOAD=${payload}"]) {
sh(script: '''
SIGNATURE=$(echo "$PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | sed 's/^.* //')
curl -s -o /dev/null -X POST "$WEBHOOK_URL" \
-H "Content-Type: application/json" \
-H "X-Hub-Signature: sha256=$SIGNATURE" \
-d "$PAYLOAD" \
--insecure
''', label: 'Notify server')
}
}
}
}
}
}
}