Skip to content

Commit dabda4e

Browse files
busbeyDuo Zhang
authored andcommitted
HBASE-26186 jenkins script for caching artifacts should verify cached file before relying on it. (#3590)
Signed-off-by: Michael Stack <stack@apache.org> Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent 2225b08 commit dabda4e

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

dev-support/Jenkinsfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pipeline {
9191
"${WORKSPACE}/component/dev-support/jenkins-scripts/cache-apache-project-artifact.sh" \
9292
--working-dir "${WORKSPACE}/downloads-yetus" \
9393
--keys 'https://www.apache.org/dist/yetus/KEYS' \
94+
--verify-tar-gz \
9495
"${WORKSPACE}/yetus-${YETUS_RELEASE}-bin.tar.gz" \
9596
"yetus/${YETUS_RELEASE}/apache-yetus-${YETUS_RELEASE}-bin.tar.gz"
9697
mv "yetus-${YETUS_RELEASE}-bin.tar.gz" yetus.tar.gz
@@ -137,6 +138,7 @@ pipeline {
137138
"${WORKSPACE}/component/dev-support/jenkins-scripts/cache-apache-project-artifact.sh" \
138139
--working-dir "${WORKSPACE}/downloads-hadoop-2" \
139140
--keys 'http://www.apache.org/dist/hadoop/common/KEYS' \
141+
--verify-tar-gz \
140142
"${WORKSPACE}/hadoop-${HADOOP2_VERSION}-bin.tar.gz" \
141143
"hadoop/common/hadoop-${HADOOP2_VERSION}/hadoop-${HADOOP2_VERSION}.tar.gz"
142144
for stale in $(ls -1 "${WORKSPACE}"/hadoop-2*.tar.gz | grep -v ${HADOOP2_VERSION}); do
@@ -164,6 +166,7 @@ pipeline {
164166
"${WORKSPACE}/component/dev-support/jenkins-scripts/cache-apache-project-artifact.sh" \
165167
--working-dir "${WORKSPACE}/downloads-hadoop-3" \
166168
--keys 'http://www.apache.org/dist/hadoop/common/KEYS' \
169+
--verify-tar-gz \
167170
"${WORKSPACE}/hadoop-${HADOOP3_VERSION}-bin.tar.gz" \
168171
"hadoop/common/hadoop-${HADOOP3_VERSION}/hadoop-${HADOOP3_VERSION}.tar.gz"
169172
for stale in $(ls -1 "${WORKSPACE}"/hadoop-3*.tar.gz | grep -v ${HADOOP3_VERSION}); do

dev-support/jenkins-scripts/cache-apache-project-artifact.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function usage {
2121
echo "Usage: ${0} [options] /path/to/download/file.tar.gz download/fragment/eg/project/subdir/some-artifact-version.tar.gz"
2222
echo ""
2323
echo " --force for a redownload even if /path/to/download/file.tar.gz exists."
24+
echo " --verify-tar-gz Only use a cached file if it can be parsed as a gzipped tarball."
2425
echo " --working-dir /path/to/use Path for writing tempfiles. must exist."
2526
echo " defaults to making a directory via mktemp that we clean."
2627
echo " --keys url://to/project/KEYS where to get KEYS. needed to check signature on download."
@@ -35,13 +36,15 @@ fi
3536

3637
# Get arguments
3738
declare done_if_cached="true"
39+
declare verify_tar_gz="false"
3840
declare working_dir
3941
declare cleanup="true"
4042
declare keys
4143
while [ $# -gt 0 ]
4244
do
4345
case "$1" in
4446
--force) shift; done_if_cached="false";;
47+
--verify-tar-gz) shift; verify_tar_gz="true";;
4548
--working-dir) shift; working_dir=$1; cleanup="false"; shift;;
4649
--keys) shift; keys=$1; shift;;
4750
--) shift; break;;
@@ -58,9 +61,18 @@ fi
5861
target="$1"
5962
artifact="$2"
6063

61-
if [ -f "${target}" ] && [ "true" = "${done_if_cached}" ]; then
62-
echo "Reusing existing download of '${artifact}'."
63-
exit 0
64+
if [ -f "${target}" ] && [ -s "${target}" ] && [ -r "${target}" ] && [ "true" = "${done_if_cached}" ]; then
65+
if [ "false" = "${verify_tar_gz}" ]; then
66+
echo "Reusing existing download of '${artifact}'."
67+
exit 0
68+
fi
69+
if ! tar tzf "${target}" > /dev/null 2>&1; then
70+
echo "Cached artifact is not a well formed gzipped tarball; clearing the cached file at '${target}'."
71+
rm -rf "${target}"
72+
else
73+
echo "Reusing existing download of '${artifact}', which is a well formed gzipped tarball."
74+
exit 0
75+
fi
6476
fi
6577

6678
if [ -z "${working_dir}" ]; then

0 commit comments

Comments
 (0)