This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
126 lines (119 loc) · 5.4 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
pipeline {
agent any
stages {
stage('Build CDAB client') {
agent {
docker {
image 'mono:6.8'
}
}
environment {
HOME = '$WORKSPACE'
}
steps {
dir("src/cdab-client") {
echo 'Build CDAB client .NET application'
sh 'msbuild /t:build /Restore:true /p:Configuration=DEBUG'
stash includes: 'bin/**,App_Data/**,cdab-client', name: 'cdab-client-build'
}
}
}
stage('Package CDAB Client') {
agent {
docker {
image 'alectolytic/rpmbuilder:centos-7'
}
}
steps {
dir("src/cdab-client") {
unstash name: 'cdab-client-build'
sh 'mkdir -p build/{BUILD,RPMS,SOURCES,SPECS,SRPMS}'
sh 'cp cdab-client.spec build/SPECS/cdab-client.spec'
sh 'spectool -g -R --directory build/SOURCES build/SPECS/cdab-client.spec'
sh 'cp -r bin build/SOURCES/'
sh 'cp -r App_Data build/SOURCES/'
sh 'cp cdab-client build/SOURCES/'
script {
def sdf = sh(returnStdout: true, script: 'date -u +%Y%m%dT%H%M%S').trim()
if (env.BRANCH_NAME == 'master') {
env.release_cdab_client = env.BUILD_NUMBER
}
else {
env.release_cdab_client = 'SNAPSHOT' + sdf
}
}
echo 'Build package'
sh "rpmbuild --define \"_topdir ${pwd()}/build\" -ba --define '_branch ${env.BRANCH_NAME}' --define '_release ${env.release_cdab_client}' build/SPECS/cdab-client.spec"
sh "rpm -qpl ${pwd()}/build/RPMS/*/*.rpm"
}
stash includes: 'src/cdab-client/build/RPMS/**/*.rpm', name: 'cdab-client-rpm'
}
}
stage('Package CDAB Remote Client') {
agent {
docker {
image 'alectolytic/rpmbuilder:centos-7'
}
}
steps {
dir("src/cdab-remote-client") {
sh 'mkdir -p build/{BUILD,RPMS,SOURCES,SPECS,SRPMS}'
sh 'cp cdab-remote-client.spec build/SPECS/cdab-remote-client.spec'
sh 'spectool -g -R --directory build/SOURCES build/SPECS/cdab-remote-client.spec'
sh 'cp -r bin build/SOURCES/'
sh 'cp -r libexec build/SOURCES/'
sh 'cp -r etc build/SOURCES/'
script {
def sdf = sh(returnStdout: true, script: 'date -u +%Y%m%dT%H%M%S').trim()
if (env.BRANCH_NAME == 'master') {
env.release_cdab_remote_client = env.BUILD_NUMBER
}
else {
env.release_cdab_remote_client = 'SNAPSHOT' + sdf
}
}
echo 'Build package'
sh "rpmbuild --define \"_topdir ${pwd()}/build\" -ba --define '_branch ${env.BRANCH_NAME}' --define '_release ${env.release_cdab_remote_client}' build/SPECS/cdab-remote-client.spec"
sh "rpm -qpl ${pwd()}/build/RPMS/*/*.rpm"
}
stash includes: 'src/cdab-remote-client/build/RPMS/**/*.rpm', name: 'cdab-remote-client-rpm'
}
}
stage('Publish RPMs') {
steps {
unstash name: 'cdab-client-rpm'
unstash name: 'cdab-remote-client-rpm'
archiveArtifacts artifacts: 'src/*/build/RPMS/**/*.rpm', fingerprint: true
}
}
stage('Build & Publish Docker') {
steps {
unstash name: 'cdab-client-rpm'
unstash name: 'cdab-remote-client-rpm'
sh "ls src/*/build/RPMS/*/"
sh "mv src/cdab-client/build/RPMS/noarch/cdab-client-*.rpm src/docker/"
sh "mv src/cdab-remote-client/build/RPMS/noarch/cdab-remote-client-*.rpm src/docker/"
script {
def cdabclientrpm = findFiles(glob: "src/docker/cdab-client-*.rpm")
def cdabremoteclientrpm = findFiles(glob: "src/docker/cdab-remote-client-*.rpm")
def descriptor = readDescriptor()
def mType=getTypeOfVersion(env.BRANCH_NAME)
def testsuite = docker.build(descriptor.docker_image_name, "--build-arg CDAB_RELEASE=${mType}${descriptor.version} --build-arg CDAB_CLIENT_RPM=${cdabclientrpm[0].name} --build-arg CDAB_REMOTE_CLIENT_RPM=${cdabremoteclientrpm[0].name} ./src/docker")
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub-emmanuelmathot') {
testsuite.push("${mType}${descriptor.version}")
testsuite.push("${mType}latest")
}
}
}
}
}
}
def getTypeOfVersion(branchName) {
def matcher = (env.BRANCH_NAME =~ /master/)
if (matcher.matches())
return ""
return "dev"
}
def readDescriptor (){
return readYaml(file: 'build.yml')
}