-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile.disabled
More file actions
112 lines (98 loc) · 4 KB
/
Copy pathJenkinsfile.disabled
File metadata and controls
112 lines (98 loc) · 4 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
properties(
[
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '30'))
]
)
node('docker') {
def contributors = null
def Utils
def imagename = 'postfix'
def vertag
def buildLabel
currentBuild.result = "SUCCESS"
stage ('Checkout Source') {
deleteDir()
doCheckout()
// load pipeline utility functions
Utils = load "utils/Utils.groovy"
vertag = Utils.getGitDescribe()
buildLabel = Utils.getBuildLabel()
}
stage ('Create Change Logs') {
sshagent(['38bf8b09-9e52-421a-a8ed-5280fcb921af']) {
try {
Utils.copyArtifactWhenAvailable("Cogosense/Postfix/${env.BRANCH_NAME}", 'SCM/CHANGELOG', 1, 0)
}
catch(err) {}
dir("./SCM") {
sh '../utils/scmBuildDate > TIMESTAMP'
writeFile file: "TAG", text: buildLabel
writeFile file: "URL", text: env.BUILD_URL
writeFile file: "BRANCH", text: env.BRANCH_NAME
sh '../utils/scmBuildContributors > CONTRIBUTORS'
sh '../utils/scmBuildOnHookEmail > ONHOOK_EMAIL'
sh "../utils/scmUpdateChangeLog -t ${buildLabel} -o CHANGELOG"
sh '../utils/scmTagLastBuild'
}
}
}
try {
contributors = readFile './SCM/ONHOOK_EMAIL'
stage ('Notify Build Started') {
Utils.sendOnHookEmail(contributors)
}
def app
stage ('Build Docker') {
dir("./src") {
app = docker.build("053262612181.dkr.ecr.us-west-2.amazonaws.com/${imagename}:${env.BUILD_NUMBER}", '--pull --no-cache .')
}
}
stage ('Push Docker') {
docker.withRegistry('https://053262612181.dkr.ecr.us-west-2.amazonaws.com', 'ecr:us-west-2:bae55279-e86a-4337-b246-ba0b28902a91') {
app.push()
app.push("${Utils.getDockerStageTag()}-${vertag}")
app.push(Utils.getDockerStageTag())
}
// Cleanup image so cache doesn't fill up
sh "docker rmi 053262612181.dkr.ecr.us-west-2.amazonaws.com/${imagename}:${env.BUILD_NUMBER} 053262612181.dkr.ecr.us-west-2.amazonaws.com/${imagename}:${Utils.getDockerStageTag()}-${vertag}"
// Don't remove the image with the stage tag - it may be currently being referenced
// by multiple concurrent build, just clean up dangling images left behind as the
// stage tag is moved forwards
}
stage ('Archive SCM') {
step([$class: 'ArtifactArchiver',
artifacts: 'SCM/**',
fingerprint: true,
onlyIfSuccessful: true])
}
}
catch(err) {
currentBuild.result = "FAILURE"
Utils.sendFailureEmail(contributors, err)
throw err
}
stage ('Notify Build Completion') {
Utils.sendOffHookEmail(contributors)
}
}
def doCheckout() {
// Required because default behaviour changed in git plugin v3.4.0
// noTags changed from false to true.
// Reguires script approval for following methods:
// method hudson.plugins.git.GitSCM getBranches
// method hudson.plugins.git.GitSCM getUserRemoteConfigs
// method hudson.plugins.git.GitSCMBackwardCompatibility getExtensions
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false]],
userRemoteConfigs: scm.userRemoteConfigs
])
// Load the SCM util scripts
checkout([$class: 'GitSCM',
branches: [[name: "*/${env.BRANCH_NAME}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'utils']],
submoduleCfg: [],
userRemoteConfigs: [[url: 'git@github.com:Cogosense/JenkinsUtils.git', credentialsId: '38bf8b09-9e52-421a-a8ed-5280fcb921af']]])
}