forked from kradalby/alertmanager-discord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
74 lines (69 loc) · 2.75 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
podTemplate(containers: [
containerTemplate(name: 'docker', image: 'docker:19.03.6', command: 'cat', ttyEnabled: true),
containerTemplate(
name: 'sonarqube',
image: 'cloudbees/java-build-tools:2.5.1',
command: 'cat',
ttyEnabled: true
),
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]
) {
node(POD_LABEL) {
def appName = "alertmanager-discord"
def appFullName
def revision
def message
def repoURL
stage('Checkout') {
def scmVars = checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [
[
$class: 'AuthorInChangelog'
],
[
$class: 'ChangelogToBranch',
options: [
compareRemote: 'origin',
compareTarget: 'main'
]
]
],
userRemoteConfigs: scm.userRemoteConfigs
])
appFullName = "${appName}:${scmVars.GIT_COMMIT}"
revision = "${scmVars.GIT_COMMIT}"
repoURL = "${scmVars.GIT_URL}"
echo repoURL
message = sh(returnStdout: true, script: "git log --oneline -1 ${revision}")
}
// Build and push the image and notify via Discord only on PR merge to main.
if (env.BRANCH_NAME == 'main') {
stage('Build Docker Image') {
container('docker') {
docker.withRegistry('https://107126629234.dkr.ecr.ap-southeast-1.amazonaws.com', 'ecr:ap-southeast-1:49feb1c9-1719-4520-aa17-67695b347b0e') {
script {
sh """docker build --network=host -f "Dockerfile" -t 107126629234.dkr.ecr.ap-southeast-1.amazonaws.com/${appFullName} ."""
}
}
}
}
stage('Push Docker Image') {
container('docker') {
docker.withRegistry('https://107126629234.dkr.ecr.ap-southeast-1.amazonaws.com', 'ecr:ap-southeast-1:49feb1c9-1719-4520-aa17-67695b347b0e ') {
script {
sh """docker push 107126629234.dkr.ecr.ap-southeast-1.amazonaws.com/${appFullName}"""
}
}
}
}
stage('Notification') {
discordSend description: "${message}", footer: "${appFullName}", result: currentBuild.currentResult, title: "$JOB_NAME", webhookURL: "$DISCORD_WEBHOOK"
}
}
}
}