def __uploadJenkins(self, step, buildIdFile, resultFile, suffix):
"""Generate upload shell script.
We cannot simply copy the artifact to the final location as this is not
atomic. Instead we create a temporary file at the repository root, copy
the artifact there and hard-link the temporary file at the final
location. If the link fails it is usually caused by a concurrent
upload. Test that the artifact is readable in this case to distinguish
it from other fatal errors.
"""
if not self.canUploadJenkins():
return ""
return "\n" + textwrap.dedent("""\
# upload artifact
cd $WORKSPACE
BOB_UPLOAD_BID="$(hexdump -ve '/1 "%02x"' {BUILDID}){GEN}"
BOB_UPLOAD_FILE="{DIR}/${{BOB_UPLOAD_BID:0:2}}/${{BOB_UPLOAD_BID:2:2}}/${{BOB_UPLOAD_BID:4}}{SUFFIX}"
if [[ ! -e ${{BOB_UPLOAD_FILE}} ]] ; then
(
set -eE
T="$(mktemp -p {DIR})"
trap 'rm -f $T' EXIT
cp {RESULT} "$T"
mkdir -p "${{BOB_UPLOAD_FILE%/*}}"
if ! ln -T "$T" "$BOB_UPLOAD_FILE" ; then
[[ -r "$BOB_UPLOAD_FILE" ]] || exit 2
fi
){FIXUP}
fi""".format(DIR=self.__basePath, BUILDID=quote(buildIdFile), RESULT=quote(resultFile),
FIXUP=" || echo Upload failed: $?" if self._ignoreErrors() else "",
GEN=ARCHIVE_GENERATION, SUFFIX=suffix))
评论列表
文章目录