-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
166 lines (130 loc) · 3.81 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
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
#!/usr/bin/env groovy
def platform2Repo = [
"centos7" : "centos7",
"centos7java11" : "centos7",
"centos7java17" : "centos7",
"almalinux9java17": "almalinux9"
]
def buildRepoName(repo, platform) {
def repoName
if (platform ==~ /^centos\d+.*/ || platform ==~ /^almalinux\d+.*/ ) {
repoName = "${repo}-rpm-${env.BRANCH_NAME}"
} else if (platform ==~ /^ubuntu\d+/) {
repoName = "${repo}-deb-${env.BRANCH_NAME}-${platform}"
} else {
error("Unsupported platform: ${platform}")
}
echo "Repo name: $repoName"
return repoName
}
def removePackages(repo, platform, platform2Repo) {
def platformRepo = platform2Repo[platform]
if (!platformRepo) {
error("Unknown platform: $platform")
}
echo "platformRepo = $platformRepo"
if (platform ==~ /^centos\d+.*/ || platform ==~ /^almalinux\d+.*/ ) {
sh "nexus-assets-remove -u ${env.NEXUS_CRED_USR} -p ${env.NEXUS_CRED_PSW} -H ${env.NEXUS_HOST} -r ${repo} -q ${platformRepo}"
} 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, platform2Repo) {
def platformRepo = platform2Repo[platform]
if (!platformRepo) {
error("Unknown platform: $platform")
}
echo "platformRepo = $platformRepo"
echo "platform = $platform"
sh "pwd"
sh "ls -latr artifacts/packages/"
if (platform ==~ /^centos\d+.*/ || platform ==~ /^almalinux\d+.*/ ) {
sh "nexus-assets-flat-upload -u ${env.NEXUS_CRED_USR} -p ${env.NEXUS_CRED_PSW} -H ${env.NEXUS_HOST} -r ${repo}/${platformRepo} -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, platform2Repo) {
return {
def repoName = buildRepoName(repo, platform)
if (env.CLEANUP_REPO) {
removePackages(repoName, platform, platform2Repo)
}
publish(repoName, platform, platform2Repo)
}
}
def publishPackages(releaseInfo,platform2Repo) {
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,platform2Repo) ]
}
parallel publishStages
}
def doPublish(platform2Repo) {
def releaseInfo = readYaml file:'release-info.yaml'
publishPackages(releaseInfo,platform2Repo)
}
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(platform2Repo)
}
}
}
stage('publish packages (beta)') {
environment {
CLEANUP_REPO = "y"
}
when {
branch 'beta'
}
steps {
script {
doPublish(platform2Repo)
}
}
}
stage('publish packages (stable)') {
when {
branch 'stable'
}
steps {
script {
doPublish(platform2Repo)
}
}
}
}
}