-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJENKINSFILE
73 lines (62 loc) · 3.17 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
/* DO NOT TOUCH: REQUIRED FOR BUILD LOGIC */
dateTime = java.time.LocalDate.now()
pipeline {
agent none
stages {
/* Let's make sure we have the repository cloned to our workspace */
stage('Clone repository') {
steps {
script {
node {
if (environment != "dev" && environment != "acc" && environment != "prod") {
error("Project name ends with " + environment + " but should end with 'dev', 'acc', or 'prod'. Example: 'build-${projectName}-dev'.")
}
checkout scm
}
}
}
}
/* This builds the actual image; synonymous to
* docker build on the command line */
stage('Build image') {
steps {
script {
node {
tagName = "${Tagname}"
if (tagName == "") {
shortCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
tagName = "${dateTime}-${shortCommit}"
}
sh 'echo "..." | sudo docker login registry.gitlab.com --username ... --password-stdin'
try {
sh "sudo docker build -t registry.gitlab.com/${gitlabPath}:${tagName} -t registry.gitlab.com/${gitlabPath}:latest-${environment} ."
} catch (Exception e) {
now = new Date()
dateTime = now.format("dd-MM-yyyy HH:mm")
commitData = sh(returnStdout: true, script: "git log -n 1 --oneline")
commitHistory = sh(returnStdout: true, script: "git log --graph --oneline -n 5 --pretty=format:\"%ad %an %s\" --date=short")
additionalMessage = ""
if (Deploy == "Build & deploy") {
additionalMessage = ": deploy aborted"
}
discordSend description: "```Check the logs to see what went wrong (probably TS errors)``````Last 5 commits:\n\n${commitHistory}```",
footer: "${projectName}-${environment} - " + dateTime + " - " + "${commitData}",
link: env.BUILD_URL + "/console",
result: "UNSTABLE",
thumbnail: "https://i.imgur.com/zSBw3LG.png",
title: "Build failed" + additionalMessage,
webhookURL: "..."
}
sh "sudo docker push registry.gitlab.com/${gitlabPath}:${tagName}"
sh "sudo docker push registry.gitlab.com/${gitlabPath}:latest-${environment}"
}
}
}
}
stage('Trigger ManifestUpdate') {
echo "triggering updatemanifestjob"
build job: 'updatemanifest', parameters: [string(name: 'DOCKERTAG', value: env.BUILD_NUMBER)]
}
}
}
```