Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab CI/CD artifact exclude not working

the artifact section of my .gitlab-ci.yml file is:

  script:
    - echo "creating artifact"    
  artifacts:
    name: "<name of my project>"
    paths:
      - $CI_PROJECT_DIR
    exclude:
      - $CI_PROJECT_DIR/deploy/*
      - $CI_PROJECT_DIR/git/*

However, the files i want to be excluded are still included; both the deploy folder and the .git folder and their contents are present when I download the artifact from git. I also get this warning when running the artifact stage of my pipeline, despite git being excluded: WARNING: Part of .git directory is on the list of files to archive . I have tried changing it from $CI_PROJECT_DIR/git/* to $CI_PROJECT_DIR/.git/*, but this makes the artifact even larger (so large that the pipeline fails and i can't download the artifact).

I have also tried removing the /* from the filepaths and also changing it to /**/*, but neither solved the issue. One very strage thing is that sometimes the artifact is smaller with the first path ending, and sometimes it is smaller when it is removed.

How can i resolve this so that the correct files are excluded and the artifact is not as large? Or is there anything else I can do to make the artifact smaller?

like image 302
Amelia Fox Avatar asked Oct 29 '25 21:10

Amelia Fox


2 Answers

Both the folder itself and its content must be excluded. Only this worked for me:

artifacts:
  paths:
    - ./
  exclude:
    - .git
    - .git/**/*

The result from GitLab job log:

...
Uploading artifacts...
./: found 9924 matching files and directories      
.git: excluded 1 files                             
.git/**/*: excluded 31 files
...
like image 117
Oleksandr Serdiuk Avatar answered Oct 31 '25 12:10

Oleksandr Serdiuk


I had the same issue. I discovered that the paths in exclude need to be relative to $CI_PROJECT_DIR so you have to remove that part from the exclude path.

The final working way is:

  script:
    - echo "creating artifact"    
  artifacts:
    name: "<name of my project>"
    paths:
      - $CI_PROJECT_DIR
    exclude:
      - deploy/**/*
      - .git/**/*
like image 37
Simone Morettini Avatar answered Oct 31 '25 12:10

Simone Morettini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!