Amelia Fox
Amelia Fox

Reputation: 41

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?

Upvotes: 4

Views: 9878

Answers (5)

Mathias Brodala
Mathias Brodala

Reputation: 6460

If you also want to exclude e.g. .gitignore and .gitattributes at the same time you can use another wildcard match:

    exclude:
      - .git/**
      - .git*

The first line will skip the content of the .git directory, the second line will skip said directory and all Git files like .gitignore.

Upvotes: 0

Oleksandr Serdiuk
Oleksandr Serdiuk

Reputation: 73

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
...

Upvotes: 7

Simone Morettini
Simone Morettini

Reputation: 391

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/**/*

Upvotes: 4

jcandan
jcandan

Reputation: 31

I think you simply missed the dot (.) in the name of the git directory. Also, as stated in other answers, use the glob syntax:

exclude:
  - $CI_PROJECT_DIR/.git/**/*

Upvotes: 2

Guy NANA
Guy NANA

Reputation: 113

You can have a deeper insights of the use of exclude keyword here in the GitLab Doc. As you'll see in the doc:

Unlike artifacts:paths, exclude paths are not recursive. To exclude all of the contents of a directory, match them explicitly rather than matching the directory itself.

So your .gitlab-ci.yml should look like :

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

Upvotes: 2

Related Questions