diff --git a/.ci/build.sh b/.ci/build.sh
index f3f8de39c..35746cff2 100644
--- a/.ci/build.sh
+++ b/.ci/build.sh
@@ -172,20 +172,26 @@ then
 	# Clean local tree of gitignored files.
 	git clean -dfX
 
+	# Recreate output directory if it was removed by git clean.
+	[ ! -d "$cwd" ] && mkdir -p "$cwd"
+
 	# Save current HEAD commit to VERSION.
 	git log --stat -1 > VERSION || rm -f VERSION
 
 	# Archive source.
-	make_tar "$cwd/$tarball_name.tar"
+	rm -f "$tarball_name.tar*"
+	make_tar "$tarball_name.tar"
 	status=$?
 
 	# Check if the archival succeeded.
 	if [ $status -ne 0 ]
 	then
 		echo [!] Tarball creation failed with status [$status]
+		rm -f "$tarball_name.tar*"
 		exit 1
 	else
 		echo [-] Source tarball [$tarball_name] created successfully
+		mv "$tarball_name.tar*" "$cwd/"
 		[ -z "$package_name" ] && exit 0
 	fi
 fi
diff --git a/.gitignore b/.gitignore
index 35f3dc8af..3d1cf31fa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,6 +30,7 @@ Makefile
 /archive_tmp
 /static2dll.*
 /VERSION
+/target
 *.zip
 *.tar
 *.tar.*