-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
141 lines (108 loc) · 2.95 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
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
#!/usr/bin/env groovy
def buildRepoName(repo, platform) {
if (platform ==~ /^centos\d+/) {
return "${repo}-rpm-${env.BRANCH_NAME}"
} else if (platform ==~ /^ubuntu\d+/) {
return "${repo}-deb-${env.BRANCH_NAME}-${platform}"
} else {
error("Unsupported platform: ${platform}")
}
}
def removePackages(repo, platform) {
if (platform ==~ /^centos\d+/) {
sh "nexus-assets-remove -u ${env.NEXUS_CRED_USR} -p ${env.NEXUS_CRED_PSW} -H ${env.NEXUS_HOST} -r ${repo} -q ${platform}"
} else if (platform ==~ /^ubuntu\d+/) {
sh "nexus-assets-remove -u ${env.NEXUS_CRED_USR} -p ${env.NEXUS_CRED_PSW} -H ${env.NEXUS_HOST} -r ${repo} -q packages"
sh "nexus-assets-remove -u ${env.NEXUS_CRED_USR} -p ${env.NEXUS_CRED_PSW} -H ${env.NEXUS_HOST} -r ${repo} -q metadata"
} else {
error("Unsupported platform: ${platform}")
}
}
def publish(repo, platform) {
if (platform ==~ /^centos\d+/) {
sh "nexus-assets-flat-upload -u ${env.NEXUS_CRED_USR} -p ${env.NEXUS_CRED_PSW} -H ${env.NEXUS_HOST} -r ${repo}/${platform} -d artifacts/packages/${platform}/RPMS"
} else if (platform ==~ /^ubuntu\d+/) {
sh "nexus-assets-flat-upload -f -u ${env.NEXUS_CRED_USR} -p ${env.NEXUS_CRED_PSW} -H ${env.NEXUS_HOST} -r ${repo} -d artifacts/packages/${platform}"
} else {
error("Unsupported platform: ${platform}")
}
}
def doPlatform(repo, platform) {
return {
def repoName = buildRepoName(repo, platform)
if (env.CLEANUP_REPO) {
removePackages(repoName, platform)
}
publish(repoName, platform)
}
}
def publishPackages(releaseInfo) {
copyArtifacts filter: 'artifacts/**', fingerprintArtifacts: true, projectName: "${releaseInfo.project}", target: '.'
def repo = releaseInfo.repo
def platforms = releaseInfo.platforms
echo "Publish for the following ${platforms}"
def publishStages = platforms.collectEntries {
[ "${env.BRANCH_NAME} - ${it}" : doPlatform(repo,it) ]
}
parallel publishStages
}
def doPublish() {
def releaseInfo = readYaml file:'release-info.yaml'
publishPackages(releaseInfo)
}
pipeline {
agent {
label 'docker'
}
options {
timeout(time: 10, unit: 'MINUTES')
}
environment {
NEXUS_HOST = "https://repo.cloud.cnaf.infn.it"
NEXUS_CRED = credentials('jenkins-nexus')
}
stages {
stage('checkout') {
steps {
deleteDir()
checkout scm
}
}
stage('publish packages (nightly)') {
environment {
CLEANUP_REPO = "y"
}
when {
branch 'nightly'
}
steps {
script {
doPublish()
}
}
}
stage('publish packages (beta)') {
environment {
CLEANUP_REPO = "y"
}
when {
branch 'beta'
}
steps {
script {
doPublish()
}
}
}
stage('publish packages (stable)') {
when {
branch 'stable'
}
steps {
script {
doPublish()
}
}
}
}
}