Backport of: https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/1978

--- gitlab-runner-v12.1.0/executors/custom/executor.go	2019-07-19 12:13:32.000000000 +0000
+++ gitlab-runner-v12.1.0/executors/custom/executor.go	2020-04-27 00:19:46.613372635 +0000
@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"io"
 	"io/ioutil"
+	"os"
 	"path/filepath"
 
 	"github.com/sirupsen/logrus"
@@ -216,6 +217,8 @@ func (e *executor) Cleanup() {
 		return
 	}
 
+	defer os.RemoveAll(e.tempDir)
+
 	// nothing to do, as there's no cleanup_script
 	if e.config.CleanupExec == "" {
 		return