This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
insights-Jenkinsfile
94 lines (82 loc) · 3.66 KB
/
insights-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
@Library("github.com/RedHatInsights/insights-pipeline-lib@v3")
import groovy.json.JsonSlurper
node {
stage ("deploy") {
checkout scm
withCredentials(bindings: [sshUserPrivateKey(credentialsId: "cloud-netstorage",
keyFileVariable: "privateKeyFile",
passphraseVariable: "",
usernameVariable: "")]) {
String APP_NAME = "application-services"
String BRANCH = env.BRANCH_NAME.replaceAll("origin/", "")
BETA = false
if (BRANCH == "prod-stable") {
PREFIX = ""
} else if (BRANCH == "prod-beta") {
PREFIX = "beta/"
BETA = true
} else if (BRANCH == "qa-stable") {
PREFIX = "stage/"
} else if (BRANCH == "qa-beta") {
PREFIX = "stage/beta/"
BETA = true
} else {
error "Bug: invalid branch name, we only support (prod/qa)-(beta/stable) and we got ${BRANCH}"
}
if (BETA == false) {
sh """
sed -i 's/\\/beta\\/apps\\/chrome\\/snippets\\//\\/apps\\/chrome\\/snippets\\//g' index.html
echo "updated ESI paths to non-beta"
echo "-------------"
cat index.html
echo "-------------"
"""
}
// Write build info into app.info.json
// We have the src info there already
def app_info = readJSON file: "./app.info.json"
app_info.build_branch = BRANCH
app_info.build_hash = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
app_info.build_id = env.BUILD_ID
writeJSON file: "./app.info.json", json: app_info
// Send Slack Notification
String SLACK_TEXT = "${APP_NAME}/${BRANCH} [STATUS] - Deploy build ${app_info.build_id} started for GIT COMMIT ${app_info.build_hash}."
slackSend message: SLACK_TEXT, color: 'black', channel: '#insights-bots'
AKAMAI_BASE_PATH = "822386"
AKAMAI_APP_PATH = "/${AKAMAI_BASE_PATH}/${PREFIX}apps/${APP_NAME}"
configFileProvider([configFile(fileId: "9f0c91bc-4feb-4076-9f3e-13da94ff3cef", variable: "AKAMAI_HOST_KEY")]) {
sh """
eval `ssh-agent`
ssh-add \"$privateKeyFile\"
cp $AKAMAI_HOST_KEY ~/.ssh/known_hosts
chmod 600 ~/.ssh/known_hosts
n=0
until [ \$n -ge 10 ]
do
rsync -arv -e \"ssh -2\" --delete-after * sshacs@cloud-unprotected.upload.akamai.com:${AKAMAI_APP_PATH} && break
n=\$[\$n+1]
sleep 10
done
"""
}
//Clear the cache for the app being deployed
openShiftUtils.withNode(image: "docker-registry.default.svc:5000/jenkins/jenkins-slave-base-centos7-python36:latest") {
//install python dependencies
sh "curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py"
sh "python3 get-pip.py --user"
sh "wget https://raw.githubusercontent.com/RedHatInsights/insights-frontend-builder-common/master/src/akamai_cache_buster/bustCache.py"
sh "wget https://raw.githubusercontent.com/RedHatInsights/insights-frontend-builder-common/master/src/akamai_cache_buster/requirements.txt"
sh "python3 -m pip install --user -r requirements.txt"
sh "export PATH=$PATH:/home/jenkins/.local/bin"
withCredentials([file(credentialsId: "jenkins-eccu-cache-purge", variable: 'EDGERC')]) {
//path to .edgerc file is now set to $EDGERC"
//Bust the current cache
sh "python3 bustCache.py $EDGERC ${APP_NAME}"
}
}
mail to: 'mas-devexp-ci@redhat.com',
subject: "Finished Running Pipeline: ${currentBuild.fullDisplayName}",
body: "The pipeline has completed this build: ${env.BUILD_URL}"
}
}
}