From 1c748f633fba763bdb98cdc337f29b35b8b81e5e Mon Sep 17 00:00:00 2001 From: Trevor Bramwell Date: Thu, 17 May 2018 12:01:40 -0700 Subject: [PATCH] Use a temporary directory for jjb-installs When jjb-verify and jjb-merge jobs get scheduled on the same static node only one can run at a time. So when jjb-merge is running any jjb-verify jobs triggered during that time fail. Change-Id: I2ba93417614977741999151cd155a4a165b0229a Signed-off-by: Trevor Bramwell --- jjb/lf-ci-jobs.yaml | 2 ++ shell/jjb-cleanup.sh | 25 +++++++++++++++++++++++++ shell/jjb-install.sh | 11 ++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 shell/jjb-cleanup.sh diff --git a/jjb/lf-ci-jobs.yaml b/jjb/lf-ci-jobs.yaml index 41eb6da6..ea45c55f 100644 --- a/jjb/lf-ci-jobs.yaml +++ b/jjb/lf-ci-jobs.yaml @@ -529,6 +529,7 @@ - shell: !include-raw-escape: - ../shell/jjb-install.sh - ../shell/jjb-merge-job.sh + - ../shell/jjb-cleanup.sh - job-template: name: '{project-name}-jjb-merge' @@ -627,6 +628,7 @@ - ../shell/jjb-install.sh - ../shell/jjb-verify-job.sh - ../shell/jjb-check-unicode.sh + - ../shell/jjb-cleanup.sh - lf-infra-gpg-verify-git-signature - job-template: diff --git a/shell/jjb-cleanup.sh b/shell/jjb-cleanup.sh new file mode 100644 index 00000000..8f5a6260 --- /dev/null +++ b/shell/jjb-cleanup.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2017 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## +echo "---> jjb-cleanup.sh" +# Cleans up the temporary directory created for the virtualenv but only if it +# exists under /tmp. This is to ensure we never attempt to blow away '/' +# through mis-set bash variables. + +# Ensure we fail the job if any steps fail. +# DO NOT set -u as virtualenv's activate script has unbound variables +set -e -o pipefail + +# shellcheck source="$WORKSPACE/.jjb.properties" disable=SC1091 +source "$WORKSPACE/.jjb.properties" +if [[ -n "$JJB_VENV" && "$JJB_VENV" =~ /tmp/.* ]]; then + rm -r "$JJB_VENV" && "$JJB_VENV removed" +fi +rm "$WORKSPACE/.jjb.properties" diff --git a/shell/jjb-install.sh b/shell/jjb-install.sh index 9351f489..86fbef71 100644 --- a/shell/jjb-install.sh +++ b/shell/jjb-install.sh @@ -14,9 +14,14 @@ echo "---> jjb-install.sh" # DO NOT set -u as virtualenv's activate script has unbound variables set -e -o pipefail -virtualenv "/tmp/v/jjb" -# shellcheck source=/tmp/v/jjb/bin/activate disable=SC1091 -source "/tmp/v/jjb/bin/activate" +# Create a virtualenv in a temporary directoy and write it down to used +# or cleaned up later; cleanup is done in the script jjb-cleanup.sh. +JJB_VENV="$(mktemp -d)" +export JJB_VENV +virtualenv "$JJB_VENV" +echo "JJB_VENV=$JJB_VENV" > "$WORKSPACE/.jjb.properties" +# shellcheck source=$VENV_DIR/bin/activate disable=SC1091 +source "$JJB_VENV/bin/activate" pip install --quiet --upgrade "pip==9.0.3" setuptools pip install --quiet --upgrade "jenkins-job-builder==$JJB_VERSION" -- 2.16.6