Stop gitlab runner to not remove a directory
Asked Answered
B

2

17

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?

Butterfingers answered 22/3, 2017 at 9:52 Comment(0)
D
8

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

Delastre answered 24/3, 2017 at 11:48 Comment(1)
Does not work for me. Neither with dependencies or needs. The runner has version 12.6Scroggins
A
5

For Gitlab Runner >= 11.10, you can use GIT_CLEAN_FLAGS

.gitlab-ci.yml:

variables:
  GIT_CLEAN_FLAGS: -ffdx -e target_directory/
script:
  - ls -al target_directory/

According to the log you posted, it is git clean which remove your target_directory.

So you can tell git clean not to remove your target_directory by setting variable GIT_CLEAN_FLAGS as documented by GitLab & git.

Apocalypse answered 23/3, 2023 at 5:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.