-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile.cd
141 lines (116 loc) · 4.76 KB
/
Jenkinsfile.cd
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!groovy
def evLibrary = library(identifier: 'evernym-aws-codebuild@v0.4.0-aws-codebuild', retriever: modernSCM(
github(credentialsId: 'evernym-github-machine-user', repoOwner: 'evernym', repository: 'jenkins-shared')
)).com.evernym.pipeline
logger = evLibrary.Logger.new(this)
notifier = evLibrary.Notifier.new(this)
logger.setGlobalLevel('TRACE')
pipelineWrapper({
nodeWrapper {
def packageName = 'libmysqlstorage'
def srcVersion
def lastRevision
def debPVersion
def cratePVersion
def goals = ['package']
def ciImageTag
def osname = 'xenial'
def prTag = "ci-$osname" // use ci project
stage('Checkout sources from SCM') {
checkout scm
}
def evernymRepo = evLibrary.EvernymRepo.new(this)
def utils = evLibrary.Utils.new(this)
def buildCtx = evLibrary.AwsCodeBuildHelper.BuildCtx.new('mysql-storage')
def awsCBHelper = evLibrary.AwsCodeBuildHelper.new(this, buildCtx)
stage('Resolve current source version') {
srcVersion = utils.srcVersion(projectType: 'rust')
logger.info("Current source version: $srcVersion")
}
stage('Resolve last revision') {
lastRevision = evernymRepo.getLastRevision {
delegate.packageName = packageName
packageSrcVersion = srcVersion
repoDistr = 'agency-dev'
}
if (lastRevision) {
logger.info("Found last revision number: $lastRevision")
} else {
logger.info("No previous revision was found")
}
}
stage('Set release parameters') {
def releaseVersion = "${lastRevision ? lastRevision[0] + 1: 1}.$BUILD_NUMBER"
debPVersion = utils.packageVersion('deb', srcVersion, releaseVersion)
logger.info("Package version for evernym repo: $debPVersion")
// TODO crate and rpm
//cratePVersion = utils.packageVersion('crate', srcVersion, releaseVersion)
//logger.info("Package version for rust registry: $cratePVersion")
}
stage("$osname: Resolve image tag") {
def _imgVersion = utils.shStdout("OSNAME=$osname make -C devops image_ci_version -s")
ciImageTag = "${_imgVersion}-${osname}-ci"
logger.info("CI docker image tag: $ciImageTag")
}
stage('Upload source to S3') {
awsCBHelper.uploadSourceToS3()
}
awsCBHelper.build() {
projectTag = "ci-$osname"
// TODO shouldn't create/update CodeBuild project assuming that CI did this before
// and no changes in settings have appeared
// env and build spec
imageTag = ciImageTag
buildspec = 'devops/aws-codebuild/buildspec.yml'
envv = [
[name: 'OSNAME', value: "$osname"],
[name: 'MAKE_GOALS', value: "${goals.join(' ')}"],
[name: 'ARTIFACTS', value: 'libmysqlstorage/target/release/libmysqlstorage*.*'],
[name: 'FPM_P_VERSION', value: debPVersion],
// [name: 'CRATE_P_VERSION', value: cratePVersion],
]
onArtifacts = {
this.stage("$osname: Archive logs") {
utils.archiveArtifacts("logs/*.out*") {
truncate = true
allowEmptyArchive = true
}
}
}
}
stage('Upload deb to Evernym repo') {
String debName
dir("${awsCBHelper.buildCtx.projects[prTag].artifactsDir}") {
debName = utils.shStdout("ls $packageName*$debPVersion*.deb")
logger.info("Uploading debian package '$debName' to evernym repo")
evernymRepo.upload {
repoDistr = 'agency_dev'
packagePath = debName
}
}
notifier.email {
subject = '$PROJECT_NAME - Build # $BUILD_NUMBER: ' + "new deb '$debName' was published"
body = ("New debian package '$debName' was built and published" +
'\n\nCheck console output at $BUILD_URL to view the results.')
}
}
/*
['agency_dev', 'agency_qa'].each { distr ->
stage("Promote deb from $distr") {
evernymRepo.promote {
repoDistr = distr
delegate.packageName = packageName
delegate.packageVersion = debPVersion
}
}
}
*/
}
}, { err ->
if (err) {
logger.error("Pipeline failed with the error $err")
}
stage("Build result notification") {
notifier.email()
}
})