This repository has been archived by the owner on Feb 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
86 lines (80 loc) · 2.39 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
77
78
79
80
81
82
83
84
85
86
properties([
parameters([
string(name: 'ARTIFACTS_BUCKET', defaultValue: 'safe-jenkins-build-artifacts'),
string(name: 'BRANCH_NAME', defaultValue: 'master')
])
])
stage('build & test') {
parallel linux: {
node('docker') {
checkout(scm)
sh("make test")
packageBuildArtifacts('linux')
uploadBuildArtifacts()
}
},
windows: {
node('windows') {
checkout(scm)
sh("make test")
packageBuildArtifacts('windows')
uploadBuildArtifacts()
}
},
macos: {
node('osx') {
checkout(scm)
sh("make test")
packageBuildArtifacts('macos')
uploadBuildArtifacts()
}
}
}
stage('deploy') {
node('docker') {
if (params.BRANCH_NAME == "master") {
checkout(scm)
retrieveBuildArtifacts()
if (versionChangeCommit()) {
withCredentials([string(
credentialsId: 'crates_io_token', variable: 'CRATES_IO_TOKEN')]) {
sh("make publish")
}
}
}
}
}
def packageBuildArtifacts(os) {
withEnv(["JENKINS_SAMPLE_BRANCH=${params.BRANCH_NAME}",
"JENKINS_SAMPLE_BUILD_NUMBER=${env.BUILD_NUMBER}",
"JENKINS_SAMPLE_BUILD_OS=${os}"]) {
sh("make package-build-artifacts")
}
}
def uploadBuildArtifacts() {
withAWS(credentials: 'aws_jenkins_build_artifacts_user', region: 'eu-west-2') {
def artifacts = sh(returnStdout: true, script: 'ls -1 artifacts').trim().split("\\r?\\n")
for (artifact in artifacts) {
s3Upload(
bucket: "${params.ARTIFACTS_BUCKET}",
file: artifact,
workingDir: "${env.WORKSPACE}/artifacts",
acl: 'PublicRead')
}
}
}
def retrieveBuildArtifacts() {
withEnv(["JENKINS_SAMPLE_BRANCH=${params.BRANCH_NAME}",
"JENKINS_SAMPLE_BUILD_NUMBER=${env.BUILD_NUMBER}"]) {
sh("make retrieve-all-build-artifacts")
}
}
def versionChangeCommit() {
shortCommitHash = sh(
returnStdout: true,
script: "git log -n 1 --pretty=format:'%h'").trim()
message = sh(
returnStdout: true,
script: "git log --format=%B -n 1 ${shortCommitHash}").trim()
return message.startsWith("Version change")
}