title: How to cache job results only for running pipeline?
body: <p>I wrote a pipline to build my Java application with Maven. I have feature branches and master branch in my Git repository, so I have to separate Maven goal <code>package</code> and <code>deploy</code>.  Therefore I created two jobs in my pipeline. Last job needs job results from first job. </p>
  
  <p>I know that I have to cache the job results, but I don't want to</p>
  
  <ul>
  <li>expose the job results to GitLab UI</li>
  <li>expose it to the next run of the pipeline</li>
  </ul>
  
  <p>I tried following solutions without success.</p>
  
  <p><strong>Using <a href="https://docs.gitlab.com/ee/ci/yaml/README.html#cache" rel="nofollow noreferrer"><code>cache</code></a></strong></p>
  
  <p>I followed <a href="https://docs.gitlab.com/ee/ci/examples/artifactory_and_gitlab/" rel="nofollow noreferrer">How to deploy Maven projects to Artifactory with GitLab CI/CD</a>:</p>
  
  <blockquote>
    <p>Caching the <code>.m2/repository</code> folder (where all the Maven files are stored), and the <code>target</code> folder (where our application will be created), is useful for speeding up the process by running all Maven phases in a sequential order, therefore, executing mvn test will automatically run <code>mvn compile</code> if necessary.</p>
  </blockquote>
  
  <p>but this solution shares job results between piplines, see <a href="https://docs.gitlab.com/ee/ci/caching/" rel="nofollow noreferrer">Cache dependencies in GitLab CI/CD</a>:</p>
  
  <blockquote>
    <p>If caching is enabled, it’s shared between pipelines and jobs at the project level by default, starting from GitLab 9.0. Caches are not shared across projects.</p>
  </blockquote>
  
  <p>and also it should not be used for caching in the same pipeline, see <a href="https://docs.gitlab.com/ee/ci/caching/#cache-vs-artifacts" rel="nofollow noreferrer">Cache vs artifacts</a>:</p>
  
  <blockquote>
    <p>Don’t use caching for passing artifacts between stages, as it is designed to store runtime dependencies needed to compile the project:</p>
    
    <p><code>cache</code>: <strong>For storing project dependencies</strong></p>
    
    <p>Caches are used to speed up runs of a given job in <strong>subsequent pipelines</strong>, by storing downloaded dependencies so that they don’t have to be fetched from the internet again (like npm packages, Go vendor packages, etc.) While the cache could be configured to pass intermediate build results between stages, this should be done with artifacts instead.</p>
    
    <p><code>artifacts</code>: <strong>Use for stage results that will be passed between stages.</strong></p>
    
    <p>Artifacts are files generated by a job which are stored and uploaded, and can then be fetched and used by jobs in later stages of the <strong>same pipeline</strong>. This data will not be available in different pipelines, but is available to be downloaded from the UI.</p>
  </blockquote>
  
  <p><strong>Using <a href="https://docs.gitlab.com/ee/ci/yaml/README.html#artifacts" rel="nofollow noreferrer"><code>artifacts</code></a></strong></p>
  
  <p>This solution is exposing the job results to the GitLab UI, see <a href="https://docs.gitlab.com/ee/ci/yaml/README.html#artifacts" rel="nofollow noreferrer"><code>artifacts</code></a>:</p>
  
  <blockquote>
    <p>The artifacts will be sent to GitLab after the job finishes and will be available for download in the GitLab UI.</p>
  </blockquote>
  
  <p>and there is no way to expire the cache after finishing the pipeline, see <a href="https://docs.gitlab.com/ee/ci/yaml/README.html#artifactsexpire_in" rel="nofollow noreferrer"><code>artifacts:expire_in</code></a>:</p>
  
  <blockquote>
    <p>The value of <code>expire_in</code> is an elapsed time in seconds, unless a unit is provided. </p>
  </blockquote>
  
  <p>Is there any way to cache job results only for the running pipline?</p>