Search code examples
gitlabgitlab-cigitlab-ci-runner

Stop gitlab runner to not remove a directory


I have a directory which is generated during a build and it should not be deleted in the next builds. I tried to keep the directory using cache in .gitlab-ci.yml:

cache:
  key: "$CI_BUILD_REF_NAME"
  untracked: true
  paths:
    - target_directory/
build-runner1:
  stage: build
  script:
    - ./build-platform.sh target_directory

In the first build a cache.zip is generated but for the next builds the target_directory is deleted and the cache.zip is extracted which takes a very long time. Here is a log of the the second build:

Running with gitlab-ci-multi-runner 1.11.
  on Runner1
Using Shell executor...
Running on Runner1...
Fetching changes...
Removing target_directory/
HEAD is now at xxxxx Update .gitlab-ci.yml
From xxxx
Checking out xxx as master...
Skipping Git submodules setup
Checking cache for master...
Successfully extracted cache

Is there a way that gitlab runner not remove the directory in the first place?


Solution

  • What you need is to use a job artifacts:

    Artifacts is a list of files and directories which are attached to a job after it completes successfully.

    .gitlab-ci.yml file:

    your job:
        before_script:
            - do something
        script:
             - do another thing
             - do something to generate your zip file (example: myFiles.zip)
      artifacts:
        paths:
             - myFiles.zip
    

    After a job finishes, if you visit the job's specific page, you can see that there is a button for downloading the artifacts archive.

    Note