-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile.github
130 lines (115 loc) · 4.04 KB
/
Jenkinsfile.github
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
@Library('csm-shared-library') _
def credentialsId = 'artifactory-algol60'
pipeline {
agent {
node { label 'metal-gcp-builder' }
}
// Configuration options applicable to the entire job
options {
// Don't fill up the build server with unnecessary cruft
buildDiscarder(logRotator(numToKeepStr: '15'))
timestamps()
}
parameters {
string(name: 'SLACK_CHANNEL', description: 'The slack channel to send upload results to. Empty to disable. For testing you can use csm-release-alerts', defaultValue: "casm_release_management")
}
environment {
GCS_PREFIX="gs://csm-release-public/hotfix"
GOOGLE_APPLICATION_CREDENTIALS=credentials('csm-gcp-release-gcs-admin')
CLOUDSDK_CONFIG="${WORKSPACE}/env/gcloud"
}
stages {
stage('Setup') {
steps {
sh '''#!/usr/bin/env bash
gcloud auth activate-service-account --key-file ${GOOGLE_APPLICATION_CREDENTIALS}
gcloud config set core/project csm-release
'''
}
}
stage('Find hotfixes to build') {
steps {
sh '''
mkdir -p dist
rm -f dist/build.txt
touch dist/build.txt
find . -maxdepth 4 -mindepth 4 -wholename '*/lib/version.sh' ! -wholename './.*' ! -wholename './vendor/*' | while read VERSION_SH; do
RELEASE="$("$VERSION_SH")"
FOLDER="$(basename "$(dirname "${VERSION_SH%/lib/version.sh}")")"
GCS_FILE="${GCS_PREFIX}/${FOLDER}/${RELEASE}.tar.gz"
echo "Looking for existing distribution ${GCS_FILE}"
if gsutil -q stat "${GCS_FILE}"; then
echo "Distribution already found for ${FOLDER}/${RELEASE}. Not rebuilding."
echo "https://storage.googleapis.com/csm-release-public/hotfix/${RELEASE}.tar.gz"
else
echo "Distribution not found for ${FOLDER}/${RELEASE}. Building."
echo "${VERSION_SH}" >> dist/build.txt
fi
done
if [ -s dist/build.txt ]; then
echo "Hotfixes to build:"
cat dist/build.txt
else
echo "Nothing to build."
fi
'''
}
}
stage('Build Hotfixes') {
steps {
withCredentials([usernamePassword(credentialsId: credentialsId, usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_TOKEN')]) {
sh '''
if [ -s dist/build.txt ]; then
while read VERSION_SH; do
HOTFIX="${VERSION_SH%%/lib/version.sh}"
echo "Building ${HOTFIX}"
./release.sh "$HOTFIX"
done < dist/build.txt
else
echo "Nothing to build."
fi
'''
}
}
}
stage('Upload to GCP') {
when {
branch 'master'
}
steps {
script {
sh '''
touch dist/slack.txt
while read VERSION_SH; do
RELEASE="$("$VERSION_SH")"
FOLDER="$(basename "$(dirname "${VERSION_SH%/lib/version.sh}")")"
GCS_FILE="${GCS_PREFIX}/${FOLDER}/${RELEASE}.tar.gz"
DIST_FILE="dist/${RELEASE}.tar.gz"
cd dist
sha256sum ${RELEASE}.tar.gz > ${RELEASE}.tar.gz.sha256.txt
cd ..
echo "Uploading ${DIST_FILE} to ${GCS_FILE}"
gsutil cp ${DIST_FILE} ${GCS_FILE}
gsutil cp ${DIST_FILE}.sha256.txt ${GCS_FILE}.sha256.txt
URL="https://storage.googleapis.com/csm-release-public/hotfix/${FOLDER}/${RELEASE}.tar.gz"
echo "Hotfix available at"
echo "${URL}"
echo "Hotfix ${RELEASE} uploaded to ${URL}" >> dist/slack.txt
done < dist/build.txt
'''
def msgs = readFile("dist/slack.txt").split("\n")
for(String msg in msgs) {
if(params.SLACK_CHANNEL != "" && msg != "") {
slackSend(channel: params.SLACK_CHANNEL, color: "good", message: msg)
}
}
}
}
}
}
post {
always {
archiveArtifacts artifacts: 'dist/**/*', fingerprint: true
}
}
}