-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkins-promote.groovy
125 lines (118 loc) · 7.29 KB
/
Jenkins-promote.groovy
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
#!groovy
//
// Jenkins-promote.groovy - Jenkins script for promoting a single Zenoss product image.
//
// This script has 4 phases:
// 1. Pull the specified docker image from docker hub, retag it per the
// "to" parameters, and push the result back to docker hub.
// 2. Recompile the service definitions to use the new image and build the
// svcdef RPM.
// 3. Push the RPM to the designated YUM repo (e.g. testing or stable).
// 4. Build appliances and offline resources based on the new image and RPM.
//
// The Jenkins job parameters for this script are:
//
// GIT_SHA - the GIT SHA of product-assembly to checkout for this build
// GIT_CREDENTIAL_ID - the UUID of the Jenkins GIT credentials used to checkout stuff from github
// PRODUCT_BUIlD_NUMBER - the build number for any given execution of this build pipeline
// TARGET_PRODUCT - identifies the target product (e.g. 'core', 'resmgr', 'ucspm', etc)
// FROM_MATURITY - required; the maturity level of the build that is
// being promoted. Must be one of unstable, testing, stable
// FROM_RELEASEPHASE - The release phase of the from build (e.g. "RC1", "BETA", etc)
// Only applies when FROM_MATURITY is testing
// TO_MATURITY - required; the maturity level of the build that will
// be created. Must be one of testing, or stable
// TO_RELEASEPHASE - The release phase of the promoted build.
// If TO_MATURITY is testing, then this value is typically something "BETA" or "RC1".
// If TO_MATURITY is stable, then this value must be a single digit such as 1.
//
node ('build-zenoss-product') {
def pipelineBuildName = env.JOB_NAME
def pipelineBuildNumber = env.BUILD_NUMBER
currentBuild.displayName = "promote ${TARGET_PRODUCT} from ${FROM_MATURITY} to ${TO_MATURITY}"
def childJobLabel = TARGET_PRODUCT + " promote to " + TO_MATURITY
stage 'Promote image'
// Make sure we start in a clean directory to ensure a fresh git clone
deleteDir()
// NOTE: The 'master' branch name here is only used to clone the github repo.
// The next checkout command will align the build with the correct target revision.
git branch: 'master', credentialsId: '${GIT_CREDENTIAL_ID}', url: 'https://github.com/zenoss/product-assembly'
sh("git checkout ${GIT_SHA}")
sh("pwd;git status")
// Get the values of various versions out of the versions.mk file for use in later stages
def versionProps = readProperties file: 'versions.mk'
def SVCDEF_GIT_REF=versionProps['SVCDEF_GIT_REF']
def ZENOSS_VERSION=versionProps['VERSION']
def ZENOSS_SHORT_VERSION=versionProps['SHORT_VERSION']
def SERVICED_BRANCH=versionProps['SERVICED_BRANCH']
def SERVICED_MATURITY=versionProps['SERVICED_MATURITY']
def SERVICED_VERSION=versionProps['SERVICED_VERSION']
def SERVICED_BUILD_NBR=versionProps['SERVICED_BUILD_NBR']
echo "SVCDEF_GIT_REF=${SVCDEF_GIT_REF}"
echo "ZENOSS_VERSION=${ZENOSS_VERSION}"
echo "ZENOSS_SHORT_VERSION=${ZENOSS_SHORT_VERSION}"
echo "SERVICED_BRANCH=${SERVICED_BRANCH}"
echo "SERVICED_MATURITY=${SERVICED_MATURITY}"
echo "SERVICED_VERSION=${SERVICED_VERSION}"
echo "SERVICED_BUILD_NBR=${SERVICED_BUILD_NBR}"
// Promote the docker images
def promoteArgs = "TARGET_PRODUCT=${TARGET_PRODUCT}\
PRODUCT_BUILD_NUMBER=${PRODUCT_BUILD_NUMBER}\
ZENOSS_VERSION=${ZENOSS_VERSION}\
ZENOSS_SHORT_VERSION=${ZENOSS_SHORT_VERSION}\
FROM_MATURITY=${FROM_MATURITY}\
FROM_RELEASEPHASE=${FROM_RELEASEPHASE}\
TO_MATURITY=${TO_MATURITY}\
TO_RELEASEPHASE=${TO_RELEASEPHASE}"
sh("cd svcdefs;${promoteArgs} ./image_promote.sh")
stage 'Compile service definitions and build RPM'
// Run the checkout in a separate directory. We have to clean it ourselves, because Jenkins doesn't (apparently)
sh("rm -rf svcdefs/build;mkdir -p svcdefs/build/zenoss-service")
dir('svcdefs/build/zenoss-service') {
// NOTE: The 'master' branch name here is only used to clone the github repo.
// The next checkout command will align the build with the correct target revision.
echo "Cloning zenoss-service - ${SVCDEF_GIT_REF} with credentialsId=${GIT_CREDENTIAL_ID}"
git branch: 'master', credentialsId: '${GIT_CREDENTIAL_ID}', url: 'https://github.com/zenoss/zenoss-service.git'
sh("pwd;git checkout ${SVCDEF_GIT_REF}")
}
// Note that SVDEF_GIT_READY=true tells the make to NOT attempt a git operation on its own because we need to use
// Jenkins credentials instead
def makeArgs = "BUILD_NUMBER=${PRODUCT_BUILD_NUMBER}\
IMAGE_NUMBER=${PRODUCT_BUILD_NUMBER}\
MATURITY=${TO_MATURITY}\
SVCDEF_GIT_READY=true\
RELEASE_PHASE=${TO_RELEASEPHASE}\
TARGET_PRODUCT=${TARGET_PRODUCT}"
sh("cd svcdefs;make build ${makeArgs}")
archive includes: 'svcdefs/build/zenoss-service/output/**'
stage 'Push RPM'
// FIXME - if we never use the pipeline to build/publish artifacts directly to the stable or
// testing repos, then maybe we should remove MATURITY as an argument for this job?
def s3Subdirectory = "/yum/zenoss/" + TO_MATURITY + "/centos/el7/os/x86_64"
build job: 'rpm_repo_push', parameters: [
[$class: 'StringParameterValue', name: 'JOB_LABEL', value: childJobLabel],
[$class: 'StringParameterValue', name: 'UPSTREAM_JOB_NAME', value: pipelineBuildName],
[$class: 'StringParameterValue', name: 'S3_BUCKET', value: 'get.zenoss.io'],
[$class: 'StringParameterValue', name: 'S3_SUBDIR', value: s3Subdirectory]
]
stage 'Build Appliances'
if (BUILD_APPLIANCES == "true") {
// NOTE: The appliance build parameter PRODUCT_BUILD_NUMBER is used for retrieving RPMs
// and labeling appliance artifacts. However, for promotion builds where MATURITY is
// testing or stable, we do not use the product build number to label the artifacts -
// we use the value of TO_RELEASEPHASE instead.
build job: 'appliance-build', parameters: [
[$class: 'StringParameterValue', name: 'JOB_LABEL', value: childJobLabel],
[$class: 'StringParameterValue', name: 'TARGET_PRODUCT', value: TARGET_PRODUCT],
[$class: 'StringParameterValue', name: 'PRODUCT_BUILD_NUMBER', value: TO_RELEASEPHASE],
[$class: 'StringParameterValue', name: 'ZENOSS_MATURITY', value: TO_MATURITY],
[$class: 'StringParameterValue', name: 'ZENOSS_VERSION', value: ZENOSS_VERSION],
[$class: 'StringParameterValue', name: 'SERVICED_BRANCH', value: SERVICED_BRANCH],
[$class: 'StringParameterValue', name: 'SERVICED_MATURITY', value: SERVICED_MATURITY],
[$class: 'StringParameterValue', name: 'SERVICED_VERSION', value: SERVICED_VERSION],
[$class: 'StringParameterValue', name: 'SERVICED_BUILD_NBR', value: SERVICED_BUILD_NBR],
]
} else {
echo "Skipped Build Appliances"
}
}