title: How to delete artifacts directory on gitlab runner after uploading them to gitlab?
body: <p>I'm trying to create a gitlab job that shows a metric for test code coverage. To do that, I'm creating a <code>.coverage</code> file and placing it in a directory that uploads artifacts. In a subsequent stage the artifacts are downloaded and consumed by a coverage tool to produce a coverage report. I noticed that the artifacts are not deleted when the gitlab runner finishes the job and are bloating my filesystem. How can I remove the artifacts directory after the artifacts are uploaded?</p>
  
  <p>Here's what we currently have</p>
  
  <pre><code>stages:
      - test
      - build
  
  before_script:
      - export GITLAB_ARTIFACT_DIR="$(pwd)"/artifacts
  
  [...]
  
  some-test:
      stage: test
      script:
          - [some script that puts something in ${GITLAB_ARTIFACTS_DIR}
      artifacts:
          expire_in: 4 days
          paths:
              - artifacts/
  some-other-test:
      stage: test
      script:
          - [some script that puts something in ${GITLAB_ARTIFACTS_DIR}
      artifacts:
          expire_in: 4 days
          paths:
              - artifacts/
  
  [...]
  coverage:
      stage: build
      before_script: 
      script: 
          - [our coverage script]
      coverage: '/TOTAL.*\s+(\d+%)$/'
      artifacts:
          expire_in: 4 days
          paths:
              - artifacts/
          when: always
  [...]
  after_script:
      - sudo rm -rf "${GITLAB_ARTIFACT_DIR}"
  
  </code></pre>
  
  <p>According to <a href="https://gitlab.com/gitlab-org/gitlab-runner/issues/4146" rel="nofollow noreferrer">https://gitlab.com/gitlab-org/gitlab-runner/issues/4146</a> <code>after_script</code> does not have access to <code>before_script</code> or <code>scripts</code> environment variables.</p>