Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete gitlab CI jobs pipelines logs/builds and history

How can we configure gitlab to keep only the last 10 CI jobs/builds and keep deleting the rest?

For example , in Jenkins , we can configure the job to keep only last X builds.

like image 723
Ijaz Ahmad Avatar asked Nov 17 '18 21:11

Ijaz Ahmad


People also ask

Where are GitLab job logs stored?

By default, all job traces (logs) are saved to /var/opt/gitlab/gitlab-ci/builds and /home/git/gitlab/builds for Omnibus packages and installations from source respectively. The job logs are organized by year and month (for example, 2017_03 ), and then by project ID.

What is CI CD pipeline in GitLab?

GitLab CI/CD is the part of GitLab that you use for all of the continuous methods (Continuous Integration, Delivery, and Deployment). With GitLab CI/CD, you can test, build, and publish your software with no third-party application or integration needed.

What are GitLab runners?

GitLab runner is a build instance which is used to run the jobs over multiple machines and send the results to GitLab and which can be placed on separate users, servers, and local machine. You can register the runner as shared or specific after installing it.


2 Answers

UPDATE

As of Gitlab Release 12.6, deleting a pipeline is now an option in the GUI for owners:

  • Click the pipeline you want to remove in the pipelines list
  • Hit the red Delete button in the upper right of the pipeline details page.

As of Gitlab Release 11.6, deleting a pipeline is now an option, for maintainers only, via the API.

You need:

  • An API token
  • The id of the project
  • The pipeline_id of the pipeline you wish to remove.

Example using curl from the docs for project id: 1 and pipeline_id: 4:

curl --header "PRIVATE-TOKEN: <your_access_token>" --request "DELETE" "https://gitlab.example.com/api/v4/projects/1/pipelines/46" 

Documentation is here

like image 124
Routhinator Avatar answered Sep 18 '22 09:09

Routhinator


Mass deletion script fixed for the lazy, delete X pipelines from the oldest.

Note: need jq.

#!/bin/bash set -e  TOKEN="" PROJECT="" # How many to delete from the oldest. PER_PAGE=100  for PIPELINE in $(curl --header "PRIVATE-TOKEN: $TOKEN" "https://gitlab.com/api/v4/projects/$PROJECT/pipelines?per_page=$PER_PAGE&sort=asc" | jq '.[].id') ; do     echo "Deleting pipeline $PIPELINE"     curl --header "PRIVATE-TOKEN: $TOKEN" --request "DELETE" "https://gitlab.com/api/v4/projects/$PROJECT/pipelines/$PIPELINE" done  
like image 26
Mog Avatar answered Sep 22 '22 09:09

Mog