forked from jenkinsci/elasticbox-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.sh
More file actions
77 lines (60 loc) · 2.55 KB
/
common.sh
File metadata and controls
77 lines (60 loc) · 2.55 KB
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
#!/bin/bash
ELASTICBOX_RELEASE="4.0"
function ebx_token() {
curl -ksf -H 'Content-Type:application/json' -X POST --data '{"email": "'$1'", "password": "'$2'"}' ${EBX_ADDRESS}/services/security/token
}
function check_online() {
curl -ksf -H "ElasticBox-Token: $1" -H "ElasticBox-Release: $2" $3/services/workspaces | grep "http://elasticbox.net/schemas/"
}
function upgrade_appliance() {
PACKAGE=${1}
EBX_ADDRESS=${2}
EBX_TOKEN=${3}
echo "Uploading package to ${EBX_ADDRESS}"
ADMIN_TOKEN=$(ebx_token test_admin@elasticbox.com elasticbox)
UPLOAD_URL="${EBX_ADDRESS}/services/appliance/upload"
RESPONSE=$(curl -k# -X POST -H "ElasticBox-Token: ${ADMIN_TOKEN}" -H "ElasticBox-Release: ${ELASTICBOX_RELEASE}" --form blob=@${PACKAGE} ${UPLOAD_URL})
if [[ -n $(echo ${RESPONSE} | grep '"message"') ]]
then
echo Error uploading ${PACKAGE} to ${UPLOAD_URL}: ${RESPONSE}
exit 1
fi
[[ -z ${EBX_TOKEN} ]] && EBX_TOKEN=${ADMIN_TOKEN}
echo "Start upgrading the appliance..."
curl -ksf -X POST -H "ElasticBox-Token: ${ADMIN_TOKEN}" -H "ElasticBox-Release: ${ELASTICBOX_RELEASE}" "${EBX_ADDRESS}/services/appliance/upgrade" || true
echo "Waiting for the appliance services to restart..."
# Make sure that the appliance is back up (polling for a while)
set +e
for i in `seq 20`
do
sleep 10
echo "...checking if the appliance is back online "$i
if [[ -n $(check_online ${EBX_TOKEN} ${ELASTICBOX_RELEASE} ${EBX_ADDRESS}) ]]
then
echo "Restart finished successfully. Appliance is online."
set -e
return
fi
done
echo "Cannot access the ElasticBox appliance at ${EBX_ADDRESS} after upgrade"
exit 1
}
JENKINS_VERSION_COMMENT='version of Jenkins this plugin is built against'
function get_jenkins_version() {
REPOSITORY_FOLDER=$1
grep "${JENKINS_VERSION_COMMENT}" ${REPOSITORY_FOLDER}/pom.xml | sed -e "s|<version>\(.*\)</version>.*|\1|" -e "s/ //g"
}
function update_pom() {
POM_FILE=$1
JENKINS_VERSION=$2
FORK_COUNT=$3
if [[ -z "${FORK_COUNT}" ]]
then
FORK_COUNT=2C
fi
sed -i.bak -e "s|\(.*\)\(<version>.*</version>\)\(.*${JENKINS_VERSION_COMMENT}.*\)|\1<version>${JENKINS_VERSION}</version>\3|" \
-e "s|\(.*\)\(<forkCount>.*</forkCount>\)|\1<forkCount>${FORK_COUNT}</forkCount>|" ${POM_FILE}
}
function get_latest_jenkins_version() {
curl -s http://repo.jenkins-ci.org/public/org/jenkins-ci/plugins/plugin/maven-metadata.xml | grep latest | sed -e "s|<latest>\(.*\)</latest>.*|\1|" -e "s/ //g"
}