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 if [ ! -f "$WORKSPACE/jenkins-config/global-vars-$silo.sh" ]; then
31 echo "WARN: jenkins-config/global-vars-$silo.sh does not exist. Skipping cloud management..."
32 echo "We highly recommend setting up global-vars-$silo.sh to manage the Jenkins global variables."
33 echo "Refer to https://docs.releng.linuxfoundation.org/projects/global-jjb/en/latest/jjb/lf-ci-jobs.html#global-environment-variables for details."
37 set +x # Ensure that no other scripts add `set -x` and print passwords
38 echo "Configuring $silo"
40 JENKINS_URL=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" url)
41 JENKINS_USER=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" user)
42 JENKINS_PASSWORD=$(crudini --get "$HOME"/.config/jenkins_jobs/jenkins_jobs.ini "$silo" password)
45 export JENKINS_PASSWORD
47 global_vars="$WORKSPACE/jenkins-config/global-vars-$silo.sh"
49 if [ ! -f "$global_vars" ]; then
50 echo "ERROR: Configuration file $global_vars not found."
54 mapfile -t vars < <(cat $global_vars)
57 for var in "${vars[@]}"; do
58 # Ignore comments and blank lines
59 if [[ $var == '#'* ]] || [ -z "$var" ]; then
63 key=$(echo $var | cut -d\= -f1)
64 value=$(echo $var | cut -d\= -f2)
65 echo " '$key': '$value'," >> insert.txt
68 # Insert variables and remove first occurrence of JENKINS_URL variable
69 echo "-----> script.groovy"
70 sed "/'JENKINS_URL'/r insert.txt" "$GROOVY_SCRIPT_FILE" \
71 | sed "0,/'JENKINS_URL'/{/'JENKINS_URL'/d}" \
75 lftools jenkins groovy script.groovy