This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
forked from shikhar/kafka-connect-dynamodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
60 lines (56 loc) · 2.93 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
node {
def scmVars = checkout scm
def appName = 'kafka-dynamo-connect'
def appNameDev = 'kafka-dynamo-connect-dev'
def gitBranch = scmVars.GIT_BRANCH.replace('origin/', '')
def gitCommitMsg = sh(script: 'git show -s --format=%B --oneline HEAD', returnStdout: true).trim()
def packageVersion = "1.0.${BUILD_NUMBER}"
def slackChannel = '#core-dev'
def md5JobName = sh ( script: "echo '${gitBranch}${BUILD_NUMBER}' | md5sum - | head -c 6", returnStdout: true )
def dockerProjectName = "kafka-dynamo-connect${md5JobName}"
def dockerRegistry = 'https://153323634045.dkr.ecr.us-west-2.amazonaws.com'
def ecrRegion = 'us-west-2'
slackSend channel: "${slackChannel}", color: '#439FE0', message: "Starting ${env.JOB_NAME} - ${env.BUILD_NUMBER} - ${gitCommitMsg} (<${env.JOB_URL}|Open>)"
currentBuild.displayName = "#${BUILD_NUMBER} - ${gitBranch}"
try {
if (gitBranch == 'master') {
stage('Publish release') {
println 'Building release Docker image...'
docker.withRegistry(dockerRegistry) {
def image = docker.build("${appName}:${packageVersion}", "--build-arg APP_VERSION=${packageVersion} .")
try {
sh "aws ecr get-login --no-include-email --region ${ecrRegion} | bash"
image.push()
image.push('latest')
} finally {
sh "docker inspect ${image.imageName()} -f '{{.Id}}' | xargs docker rmi -f"
sh "docker image prune --force --filter label=stage=intermediate"
}
}
}
}
else if (gitBranch == 'develop') {
stage('Publish non-prod release') {
println 'Building Docker image...'
docker.withRegistry(dockerRegistry) {
def image = docker.build("${appNameDev}:${packageVersion}", "--build-arg APP_VERSION=${packageVersion} .")
try {
sh "aws ecr get-login --no-include-email --region ${ecrRegion} | bash"
image.push()
image.push('latest')
} finally {
sh "docker inspect ${image.imageName()} -f '{{.Id}}' | xargs docker rmi -f"
sh "docker image prune --force --filter label=stage=intermediate"
}
}
}
}
} catch (exc) {
slackSend channel: "${slackChannel}", color: '#FF0000', message: "${env.STAGE_NAME} failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER} - ${gitBranch} (<${env.JOB_URL}|Open>)"
currentBuild.result = 'FAILURE'
throw exc
} finally {
println 'Finishing up...'
}
slackSend channel: "${slackChannel}", color: '#439FE0', message: "Finished ${env.JOB_NAME} - ${env.BUILD_NUMBER} - ${gitBranch} (<${env.JOB_URL}|Open>)"
}