Fix rtd merge job to handle new tag uploaded
[releng/global-jjb.git] / jenkins-init-scripts / lf-env.sh
1 #!/usr/bin/no-execute
2
3 # SPDX-License-Identifier: EPL-1.0
4 ##############################################################################
5 # Copyright (c) 2019 The Linux Foundation and others.
6 #
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Eclipse Public License v1.0
9 # which accompanies this distribution, and is available at
10 # http://www.eclipse.org/legal/epl-v10.html
11 ##############################################################################
12
13 # A library of functions for LF/Jenkins bash scripts. In the general case, do
14 # NOT set shell variables here. If you want to make a variable available,
15 # provide a function that sets the variable: 'function lf_set_foo()
16 # {foo=asdf;}'. Any scripts that need access to the variable can call the 'set'
17 # function. This keeps the name-space polution to a minimum.
18
19 ################################################################################
20 # Functions
21 ################################################################################
22
23 # Execute pip from 'user' venv
24 function lf-pip() { /home/jenkins/.local/bin/pip "$@" ; }
25
26 # Echo all arguments to stderr
27 function lf-echoerr() { echo "$@" 1>&2; }
28
29 # Function to safely evaluate booleans
30 # If the boolean equal '' it is an Fatal Error
31 # Note the case of boolean will be ignored (always mapped to lower-case)
32 function lf-boolean()
33 {
34     if [[ $# != 1 ]]; then
35         echo "lf-boolean(): Missing boolean operand"
36         exit 1
37     fi
38     local bool
39     bool=$(echo "$1" | tr '[:upper:]' '[:lower:]')
40     if [[ -z $bool ]] ; then
41         # Output script name & line number of call to function
42         lf-echoerr "ERROR: $(basename $0) line: ${BASH_LINENO[0]} : A boolean cannot be a empty string" >&2
43         exit 1
44     fi
45     $bool
46 }
47
48 # Function to activate a Python Virtual Environment
49 # Just validate the path and add 'bin' to the path
50 function lf-activate()
51 {
52     if [[ $# != 1 ]]; then
53         echo "lf-activate(): Missing path operand"
54         exit 1
55     fi
56     local venv_path=$1
57     # Validate the path to a VENV
58     if [[ ! -d $venv_path/bin ]]; then
59         lf-echoerr "ERROR: Is '$venv_path' a Python Environment ?"
60         return 1
61     fi
62     PATH=$venv_path/bin:$PATH
63 }
64
65 ################################################################################
66 # Functions that assign Variables
67 ################################################################################
68
69 # Although these variables are 'shell' variables, they need to be upper-case so
70 # 'shellcheck' does check for 'used-before-set' when they are referenced. So if
71 # forget to 'source' this file, you will get a 'run-time' error (if you have -u
72 # set), otherwise you will get "MAVEN_OPIONS=''.
73
74 function lf-set-maven-options()
75 {
76     # shellcheck disable=SC2034  # Disable 'unused-variable' check
77     MAVEN_OPTIONS=$(echo --show-version --batch-mode -Djenkins \
78         -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
79         -Dmaven.repo.local=/tmp/r -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r)
80 }