69d1534bb176a4ca32c950692f62e6db01e8a8ca
[releng/global-jjb.git] / shell / jjb-cleanup.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
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 echo "---> jjb-cleanup.sh"
12 # Cleans up the temporary directory created for the virtualenv but only if it
13 # exists under /tmp. This is to ensure we never attempt to blow away '/'
14 # through mis-set bash variables.
15
16 # Ensure we fail the job if any steps fail.
17 # DO NOT set -u as virtualenv's activate script has unbound variables
18 set -e -o pipefail
19
20 # shellcheck source="$WORKSPACE/.jjb.properties" disable=SC1091
21 source "$WORKSPACE/.jjb.properties"
22 if [[ -n "$JJB_VENV" && "$JJB_VENV" =~ /tmp/.* ]]; then
23     rm -rf "$JJB_VENV" && echo "$JJB_VENV removed"
24     unset JJB_VENV
25 fi
26 rm -f "$WORKSPACE/.jjb.properties"
27 deactivate