-
Notifications
You must be signed in to change notification settings - Fork 37
/
jenkins-reload-jcasc-only.sh
executable file
·70 lines (62 loc) · 3.04 KB
/
jenkins-reload-jcasc-only.sh
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
#! /usr/bin/env bash
#*******************************************************************************
# Copyright (c) 2019 Eclipse Foundation and others.
# This program and the accompanying materials are made available
# under the terms of the Eclipse Public License 2.0
# which is available at http://www.eclipse.org/legal/epl-v20.html,
# or the MIT License which is available at https://opensource.org/licenses/MIT.
# SPDX-License-Identifier: EPL-2.0 OR MIT
#*******************************************************************************
# Bash strict-mode
set -o errexit
set -o nounset
set -o pipefail
IFS=$'\n\t'
SCRIPT_FOLDER="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
if [[ "${#}" -eq 0 ]]; then
echo "ERROR: you must provide at least one 'instance' path"
exit 1
fi
reload() {
local instance="${1}"
local projectShortName
#local configjson="${instance}/target/config.json"
projectShortName="$(jq -r '.project.shortName' "${instance}/target/config.json")"
projectFullName="$(jq -r '.project.fullName' "${instance}/target/config.json")"
#shellcheck disable=SC1091
. "${SCRIPT_FOLDER}/build/k8s-set-context.sh" "$(jq -r '.deployment.cluster' "${instance}/target/config.json")"
local previousConfigMapVersion
if "${SCRIPT_FOLDER}/build/kubectlw" -p "${projectFullName}" -- get configmap jenkins-config &> /dev/null; then
previousConfigMapVersion="$("${SCRIPT_FOLDER}/build/kubectlw" -p "${projectFullName}" -- get configmap jenkins-config -o json | jq -r '.metadata.resourceVersion')"
fi
"${SCRIPT_FOLDER}/build/kubectlw" -p "${projectFullName}" -- apply -f "${instance}/target/k8s/configmap-jenkins-config.yml"
if [[ -n "${previousConfigMapVersion:-}" ]]; then
local newConfigMapVersion
newConfigMapVersion="$("${SCRIPT_FOLDER}/build/kubectlw" -p "${projectFullName}" -- get configmap jenkins-config -o json | jq -r '.metadata.resourceVersion')"
if [[ "${previousConfigMapVersion}" != "${newConfigMapVersion}" ]]; then
local remoteConfig
remoteConfig=$(mktemp)
"${SCRIPT_FOLDER}/build/ocw" -p "${projectFullName}" -- rsh "${projectShortName}-0" cat "/etc/jenkins/jenkins.yaml" > "${remoteConfig}"
diff -Z -B "${remoteConfig}" "${instance}/target/jenkins/configuration.yml" || :
echo -n "Waiting for the Jenkins CasC config map to be updated on the pod..."
while ! diff -Z -B "${remoteConfig}" "${instance}/target/jenkins/configuration.yml" > /dev/null; do
sleep 5
echo -n "."
"${SCRIPT_FOLDER}/build/ocw" -p "${projectFullName}" -- rsh "${projectShortName}-0" cat "/etc/jenkins/jenkins.yaml" > "${remoteConfig}"
done
echo -e "\n"
rm -f "${remoteConfig}"
fi
fi
echo "Reloading Jenkins CasC file..."
"${SCRIPT_FOLDER}/jenkins-cli.sh" "${instance}" "reload-jcasc-configuration" || :
}
for instance in "${@}"; do
if [[ ! -d "${instance}" ]] || [[ ! -f "${instance}/jiro.jsonnet" ]]; then
echo "ERROR: no 'instance' at path '${instance}'"
exit 1
else
echo "INFO: Reloading configuration of $(basename "${instance}")"
reload "${instance}"
fi
done