2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2018 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 # Pulls global variable definitions out of a file.
13 # Configuration is read from $WORKSPACE/jenkins-config/global-vars-$silo.sh
15 # Requirements: lftools must be installed to /tmp/v/lftools
17 # jenkins_silos: Space separated list of Jenkins silos to push global-vars
18 # configuration to. (default: jenkins)
19 echo "---> jenkins-configure-global-vars.sh"
21 GROOVY_SCRIPT_FILE="jjb/global-jjb/jenkins-admin/set_global_properties.groovy"
23 # shellcheck source=/tmp/v/lftools/bin/activate disable=SC1091
24 source "/tmp/v/lftools/bin/activate"
25 silos="${jenkins_silos:-jenkins}"
29 for silo in $silos; do
30 set +x # Ensure that no other scripts add `set -x` and print passwords
31 echo "Configuring $silo"
33 JENKINS_URL=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" url)
34 JENKINS_USER=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" user)
35 JENKINS_PASSWORD=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" password)
38 export JENKINS_PASSWORD
40 global_vars="$WORKSPACE/jenkins-config/global-vars-$silo.sh"
42 if [ ! -f "$global_vars" ]; then
43 echo "ERROR: Configuration file $global_vars not found."
47 mapfile -t vars < <(cat $global_vars)
50 for var in "${vars[@]}"; do
51 # Ignore comments and blank lines
52 if [[ $var == '#'* ]] || [ -z "$var" ]; then
56 key=$(echo $var | cut -d\= -f1)
57 value=$(echo $var | cut -d\= -f2)
58 echo " '$key': '$value'," >> insert.txt
61 # Insert variables and remove first occurrence of JENKINS_URL variable
62 echo "-----> script.groovy"
63 sed "/'JENKINS_URL'/r insert.txt" "$GROOVY_SCRIPT_FILE" \
64 | sed "0,/'JENKINS_URL'/{/'JENKINS_URL'/d}" \
68 lftools jenkins groovy script.groovy