Although its very late but I recently had the same issue.
Issue is because dir .
is changing as xyz.tar.gz
is created after running the command. There are two solutions:
Solution 1:
tar
will not mind if the archive is created in any directory inside .
. There can be reasons why can't create the archive outside the work space. Worked around it by creating a temporary directory for putting the archive as:
mkdir artefacts
tar -zcvf artefacts/archive.tar.gz --exclude=./artefacts .
echo $?
0
Solution 2: This one I like. create the archive file before running tar:
touch archive.tar.gz
tar --exclude=archive.tar.gz -zcvf archive.tar.gz .
echo $?
0