Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab generate a zip with chosen folders

In Gitlab, is there a way with CI/CD or another trick to generate a .zip package with chosen folders after each commit? A script to use in CI/CD ?

I know we can download a whole repository with the button "download source code" but I need to create a package .zip with only some folders of the repository.

Thanks :).

like image 315
L01C Avatar asked Sep 02 '25 10:09

L01C


1 Answers

You can either generate a artifact or publish the file as a generic package.

Artifact

empaquetar:
  image: alpine
  before_script:
    - apk add --update zip
  script:
    - zip -r content.zip folder1 folder2
  artifacts:
    paths:
      - content.zip
    when: on_success

Package

empaquetar:
  image: alpine
  before_script:
    - apk add --update zip curl
  script:
    - zip -r content.zip folder1 folder2
    - 'curl 
        --header "JOB-TOKEN: $CI_JOB_TOKEN"
        --upload-file content.zip
        "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/Content/1.0.0/content.zip"'

Where Content in generic/Content/1.0.0 is the package name and 1.0.0 the version.

You can also use $CI_COMMIT_TAG variable as version if the pipeline executes only on tagged branch with a condition like this:

empaquetar:
  image: alpine
  script:
    - zip -r content.zip folder1 folder2
    - 'curl 
        --header "JOB-TOKEN: $CI_JOB_TOKEN"
        --upload-file content.zip
        "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/Content/${CI_COMMIT_TAG}/content.zip"'
  only:
    variables:
      - $CI_COMMIT_TAG =~ /^\d+.\d+.\d+*$/
like image 84
OscarGarcia Avatar answered Sep 07 '25 16:09

OscarGarcia