-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpipeline-rpm-script
94 lines (94 loc) · 3.38 KB
/
pipeline-rpm-script
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
pipeline {
agent {
label 'noiro-build-101.cisco.com'
}
options {
timestamps()
disableConcurrentBuilds()
}
environment {
DOCKER_USER = 'noiro'
DOCKER_TAG = 'latest'
BASEIMAGE = 'noiro/opflex-rpm-build-base:master-test'
BRANCH = 'master'
RPM_DIR = "$WORKSPACE/docker/rpms"
SIGNED_RPMS = "$WORKSPACE/rpmbuild/RPMS/noarch"
ARTIFACTORY_USER = 'noiro.gen'
ARTIFACTORY_URL = 'https://engci-maven.cisco.com/artifactory'
ARTIFACT_URL = 'https://engci-maven.cisco.com/artifactory/noiro-snapshot/opflex/master/rhel8/agent/$BUILD_NUMBER'
}
stages {
stage('Build Opflex RPMS') {
steps {
script {
sh """
cd docker/rpms; ./build_opflexrpm.sh ${env.DOCKER_USER} ${env.DOCKER_TAG} ${env.BASEIMAGE} ${env.BRANCH} $BUILD_NUMBER
"""
}
}
}
stage('Extract RPM Tar File') {
steps {
script {
def tarFile = "opflexrpms-${BUILD_NUMBER}.tar.gz"
sh """
rm -rf ${SIGNED_RPMS}
mkdir -p ${SIGNED_RPMS}
tar -xf ${RPM_DIR}/${tarFile} -C ${SIGNED_RPMS}
"""
}
}
}
stage('Sign RPM') {
steps {
withCredentials([
conjurSecretCredential(credentialsId: 'noiro-conjur-keeper-role-id', variable: 'KEEPER_ROLE_ID'),
conjurSecretCredential(credentialsId: 'noiro-conjur-keeper-secret-id', variable: 'KEEPER_SECRET')
]) {
script {
def signUser1 = params.SIGNUSER1 ?: 'empty'
// Handle empty params.SIGNUSER2 and pass empty string if it is
def signUser2 = params.SIGNUSER2 ?: 'empty'
// Execute sign-rpm.sh with Vault credentials passed as parameters
sh """
./docker/rpms/sign-rpm.sh ${SIGNED_RPMS} ${signUser1} ${signUser2} ${params.ReleaseBuild}
"""
}
}
}
}
stage('Push artifacts') {
steps {
script {
withCredentials([
conjurSecretCredential(credentialsId: 'noiro-conjur-artifactory-token', variable: 'ARTIFACT_TOKEN')
]) {
script {
sh """
for rpm in ${SIGNED_RPMS}/opflexrpms-${BUILD_NUMBER}/*.rpm
do curl -v -u ${ARTIFACTORY_USER}:\${ARTIFACT_TOKEN} -X PUT "${ARTIFACT_URL}/\$(basename \$rpm)" -T "\$rpm"
done
"""
}
}
}
}
}
stage('Re-Tar Signed RPMs') {
steps {
script {
def tarFile = "signed-opflexrpms-${BUILD_NUMBER}.tar.gz"
sh """
cd ${SIGNED_RPMS}
tar -czf ${SIGNED_RPMS}/${tarFile} *
"""
}
}
}
}
post {
always {
cleanWs(deleteDirs: true)
}
}
}