diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2019-01-13 09:31:40 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2019-01-13 09:32:45 +0000 |
commit | 72d44507be59f6b19d138079688a14785b485d1a (patch) | |
tree | 918cee91e24255cdd8741d76f06cac227c64ef5f | |
parent | 86ea496c22e0185614a0476ea9e4d004c8171dd3 (diff) |
jenkins-helpers.sh: New helper fresh_dir
Change-Id: I1513712e64500712a5540b9b5a5bd8e1228334c4
-rw-r--r-- | jenkins-helpers.sh | 34 | ||||
-rw-r--r-- | round-robin.sh | 9 |
2 files changed, 38 insertions, 5 deletions
diff --git a/jenkins-helpers.sh b/jenkins-helpers.sh index 8a906056..3f8135b3 100644 --- a/jenkins-helpers.sh +++ b/jenkins-helpers.sh @@ -10,6 +10,40 @@ assert () ) } +# Cleanup contents of directory preserving specified parts. +# $1: Directory to clean +# $@: Find patterns of files to preserve (must start with $1) +fresh_dir () +{ + ( + set -euf -o pipefail + + local dir="$1" + shift 1 + + # Make sure $dir doesn't have "/" at the end. + dir=$(dirname "$dir/something") + + mkdir -p "$dir" + + find_opts=("!" "-path" "$dir") + for keep_pattern in "$@"; do + while : ; do + find_opts+=("!" "-path" "$keep_pattern") + keep_pattern=$(dirname "$keep_pattern") + if [ x"$keep_pattern" = x"$dir" ]; then + break + fi + # This assert will trigger if one of keep_patterns doesn't start + # with "$dir". + assert [ "$keep_pattern" != "." ] + done + done + + find "$dir" "${find_opts[@]}" -print0 | xargs -0 rm -rf + ) +} + # $@: Jenkins labels # Prints nodes corresponding to jenkins labels. print_nodes_in_labels () diff --git a/round-robin.sh b/round-robin.sh index e257b776..2a74c049 100644 --- a/round-robin.sh +++ b/round-robin.sh @@ -45,11 +45,10 @@ reset_artifacts () # - ${rr[top_artifacts]}/console.log and $run_step_artifacts/console.log, which # are being written to by run_step(). # - ${rr[top_artifacts]}/jenkins/*, which is cleaned by tcwg_kernel.yaml. - find ${rr[top_artifacts]} -maxdepth 2 \ - ! -path ${rr[top_artifacts]} ! -path ${rr[top_artifacts]}/console.log \ - ! -path $run_step_artifacts ! -path $run_step_artifacts/console.log \ - ! -path ${rr[top_artifacts]}/jenkins ! -path "${rr[top_artifacts]}/jenkins/*" \ - -print0 | xargs -0 rm -rf + fresh_dir ${rr[top_artifacts]} \ + ${rr[top_artifacts]}/console.log \ + $run_step_artifacts/console.log \ + "${rr[top_artifacts]}/jenkins/*" # Set success metric to worst possible (-10). echo "Starting build" > ${rr[top_artifacts]}/results |