This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
76 lines (66 loc) · 3 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
// Auto-Generated by Lighthouse
import groovy.json.JsonSlurperClassic
def hasDockerBuilds = false
pipeline {
agent {
label 'docker'
}
stages {
stage('Checkout') {
steps {
sh "curl -XPUT https://lighthouse.bombbomb.io/hooks/build/bombbomb/spamassassin-node-api/${env.BRANCH_NAME}/start"
checkout scm
}
}
stage('Build Images') {
steps {
script {
def lighthouseFile = readFile "lighthouse.json"
def lighthouseJSON = new JsonSlurperClassic().parseText(lighthouseFile)
if (lighthouseJSON.service && lighthouseJSON.service.default && lighthouseJSON.service.default.build) {
echo 'Has Docker Builds'
hasDockerBuilds = true
sh "docker build -t build-${env.BUILD_NUMBER} ."
} else {
echo 'No Docker Builds Found'
}
}
}
}
stage('Deploy to ECR') {
steps {
script {
env.GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
env.GIT_DATE = sh(returnStdout: true, script: "git log -1 --format=%cd --date=format:'%Y%m%d%H%M%S'").trim()
if (hasDockerBuilds) {
env.REGISTRY_ID = sh(returnStdout: true, script: 'aws s3 cp s3://bombbomb-lighthouse/registry_lookup/bombbomb/spamassassin-node-api -').trim()
sh "eval \$(aws ecr get-login --region us-east-1 --registry-ids ${env.REGISTRY_ID})"
sh "docker tag build-${env.BUILD_NUMBER}:latest ${env.REGISTRY_ID}.dkr.ecr.us-east-1.amazonaws.com/bombbomb/spamassassin-node-api:${env.GIT_COMMIT}"
sh "docker push ${env.REGISTRY_ID}.dkr.ecr.us-east-1.amazonaws.com/bombbomb/spamassassin-node-api:${env.GIT_COMMIT}"
}
}
}
}
stage('Cleanup Image') {
steps {
script {
if (hasDockerBuilds) {
sh "docker rmi build-${env.BUILD_NUMBER}"
}
}
}
}
stage('Save Build Details') {
steps {
sh 'git log -1 --pretty=format:\'{%n "commit": "%H",%n "author": "%aN <%aE>",%n "date": "%ad",%n "message": "%f"%n}\'' + " > ${env.GIT_COMMIT}_details.txt"
sh "aws s3api put-object --bucket bombbomb-lighthouse --key builds/bombbomb/spamassassin-node-api/${env.BRANCH_NAME}/${env.GIT_DATE} --body ${env.GIT_COMMIT}_details.txt"
sh "rm ${env.GIT_COMMIT}_details.txt"
}
}
}
post {
always {
sh "curl -XPUT https://lighthouse.bombbomb.io/hooks/build/bombbomb/spamassassin-node-api/${env.BRANCH_NAME}/finish"
}
}
}