forked from wavesplatform/Waves
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreleaseJenkinsfile
176 lines (159 loc) · 8.21 KB
/
releaseJenkinsfile
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env groovy
import groovy.json.JsonOutput
import devops.waves.*
@Library('jenkins-shared-lib')
ut = new utils()
def artifactsDir="out"
def networks
def artifacts
def shaSumField = "## SHA256 Checksums\n```\n"
def user = "wavesplatform"
def repo = "Waves"
def repoUrl = "https://github.com/${user}/${repo}"
def dockerImageName = "wavesplatform/wavesnode"
def dockerImage
def wavesVersion
def useNodeSbtCache = false
def dockerRegistryCreds = 'dockerhub-wavesnode-creds'
properties([
ut.buildDiscarderPropertyObject('14', '30'),
parameters([
ut.stringParameterDefinitionObject('tag','v0.0.0'),
ut.gitParameterDefinitionObject('branch', 'origin/(version-.*)', 'ASCENDING_SMART', 'NONE', repoUrl),
ut.extendedChoiceParameterDefinitionObject("network", "mainnet,testnet,stagenet", "mainnet", 0, "" ),
ut.cascadeChoiceParameterObject('dockerTags', "return ['latest:selected', binding.variables.get('tag').replace('v', '')+':selected' ]", 'tag','PARAMETER_TYPE_CHECK_BOX'),
ut.extendedChoiceParameterDefinitionObject('useNodeSbtCache', "yes", "yes", 0, "")
])
])
stage('Build information'){
if (! params.tag || params.branch.contains('No values in a list') || ! params.network )
{
echo "Aborting this build. Please run it again with the required parameters specified"
currentBuild.result = Constants.PIPELINE_ABORTED
return
}
else
{
networks = network.split(',').collect{it.toLowerCase()}
echo "Parameters are specified:" + params
if (params.useNodeSbtCache == "yes"){
useNodeSbtCache = true
}
}
}
if (currentBuild.result == Constants.PIPELINE_ABORTED){
return
}
node('wavesnode'){
currentBuild.result = Constants.PIPELINE_SUCCESS
timestamps {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
try {
currentBuild.displayName = "#${env.BUILD_NUMBER} - ${branch} - release ${tag}"
stage('Checkout') {
sh 'env'
step([$class: 'WsCleanup'])
ut.checkout(branch, repoUrl)
sh "mkdir -p ${artifactsDir}/all"
}
stage ('Build artifacts'){
dir ('docker'){
wavesVersion = tag.replace('v','')
def specifiedNetworks = networks.join(" ")
if (useNodeSbtCache){
def text = readFile "Dockerfile"
sh """
cp -R ${env.HOME}/.ivy2 ./.ivy2
cp -R ${env.HOME}/.sbt ./.sbt
mkdir -p ./.ivy2 ./.sbt
"""
replacement="as builder\nCOPY ./.ivy2 /root/.ivy2\nCOPY ./.sbt /root/.sbt"
writeFile file: "Dockerfile", text: text.replace('as builder', replacement)
}
def dockerImageBuilder = ut.buildDockerImage('', dockerRegistryCreds, 'wavesbuilder', wavesVersion, "--build-arg WAVES_VERSION=${wavesVersion} --build-arg 'DEB_PACKCAGE_NETWORKS=${specifiedNetworks}' --build-arg BRANCH=${branch} --target builder --no-cache", true)
dockerImage = ut.buildDockerImage('', dockerRegistryCreds, dockerImageName, wavesVersion, "--build-arg WAVES_VERSION=${wavesVersion} --build-arg 'DEB_PACKCAGE_NETWORKS=${specifiedNetworks}' --build-arg BRANCH=${branch}", true)
sh """
id=\$(docker create wavesbuilder:${wavesVersion})
docker cp \${id}:/out "${env.WORKSPACE}"
docker rm -v \${id}
"""
networks.each {
def networkIdentifier = (it == 'mainnet') ? '' : '-' + it
sh """
mv "${env.WORKSPACE}/${artifactsDir}/${it}"/*.jar "${env.WORKSPACE}/${artifactsDir}/all/"
mv "${env.WORKSPACE}/${artifactsDir}/${it}"/*.tgz "${env.WORKSPACE}/${artifactsDir}/all/"
cp "${env.WORKSPACE}/${artifactsDir}/${it}"/*.deb "${env.WORKSPACE}/${artifactsDir}/all/"
"""
}
}
dir (artifactsDir + '/all'){
artifacts = findFiles(glob: '**/*')
artifacts.each{
shaSumField += ut.shWithOutput("shasum -a 256 ${it.name}") + "\n"
}
}
}
stage ('Create a release'){
withCredentials([string(credentialsId: 'waves-release-github-token', variable: 'token')]) {
dir (artifactsDir + '/all'){
def createReleaseBody = [
tag_name: "${tag}",
target_commitish: "${branch}",
name: "Version ${tag.replace('v','')} (${networks.collect{ it.capitalize() }.join(" + ")})",
body: "# In this release\n${shaSumField}```",
draft: true,
prerelease: false]
def createReleaseBodyJson = JsonOutput.toJson(createReleaseBody)
def createReleaseUrl = "https://api.github.com/repos/${user}/${repo}/releases"
def id = ut.shWithOutput "curl -s -H 'Authorization:token ${token}' -X 'POST' -H 'Content-Type: application/json' -d '${createReleaseBodyJson}' ${createReleaseUrl} | grep -m 1 'id.:' | tr -cd '[0-9]='"
artifacts.each{
def contentType = (it.name.contains('tgz')) ? "application/gzip" : "application/octet-stream"
def uploadAssetsUrl = "https://uploads.github.com/repos/${user}/${repo}/releases/${id}/assets?name=${it.name}"
sh "curl -s -H 'Authorization:token ${token}' -X 'POST' -H 'Content-Type: ${contentType}' --data-binary @${it.name} ${uploadAssetsUrl}"
}
}
}
}
withCredentials([sshUserPrivateKey(credentialsId: Constants.DEPLOYBOT_CREDS_ID, keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) {
def remote = [:]
remote.host = Constants.APT_REPO_CONTROLLER_SERVER
remote.name = Constants.APT_REPO_CONTROLLER_SERVER
remote.user = userName
remote.identityFile = identity
remote.allowAnyHosts = true
stage ('Updating APT repo'){
networks.each {
ut.remotePut(remote, "${artifactsDir}/${it}", Constants.APT_PUBLISH_DIR)
}
ut.remoteExec (remote, "${Constants.APT_PUBLISH_DIR}/publish.sh")
}
}
stage ('Pushing docker image'){
docker.withRegistry('', dockerRegistryCreds) {
if (dockerTags.contains(wavesVersion)){
dockerImage.push()
}
if (dockerTags.contains('latest')){
dockerImage.push("latest")
}
}
}
}
catch (err) {
currentBuild.result = Constants.PIPELINE_FAILURE
println("ERROR caught")
println(err)
println(err.getMessage())
println(err.getStackTrace())
println(err.getCause())
println(err.getLocalizedMessage())
println(err.toString())
}
finally{
sh "tar -czvf artifacts.tar.gz -C ${artifactsDir} ."
archiveArtifacts artifacts: 'artifacts.tar.gz'
ut.notifySlack("jenkins-notifications", currentBuild.result)
}
}
}
}