Search code examples
gitlabcontinuous-integrationreporting

How can I verify the CI artifact retention period and report on existing artifact expiration?


In the gitlab-ci file, artifact retention can be set with expire_in, and if no expiration is given then git defaults to 30 days, unless overridden or the artifact was generated before June 22, 2020

I’m working on a project to unify our pipeline configs and am unable to find where to view our artifact's expiration dates. On the individual pipeline steps, there is a message that states expiration time, but I can’t find how to see this for an entire project or group.

To my surprise, I can’t find anything in the Git documentation on how to view or report on this.

Does anyone have suggestions for how to check artifact expiration times for a project, or a group?


Solution

  • We can retrieve metadata for all jobs of a project by using the Project API https://docs.gitlab.com/ee/api/jobs.html#list-project-jobs

    GET /projects/:id/jobs
    

    Since in your case you need info for Expiration date we will also utilize jq command, in order to query for the required info

    Command:

    curl -s  --header "PRIVATE-TOKEN: <access_token>" "https://gitlab.com/api/v4/projects/<project_id>/jobs?per_page=10000000" |  jq '.[] | select (.artifacts[].file_type=="archive") |"JobId=\(.id) JobName=\(.name) JobCreationTime=\(.created_at) ArtifactExpirationDate=\(.artifacts_expire_at)"'
    

    The ouput would contain job id, name, creation time and artifact expiration date for the jobs of a specific project E.g.

    "JobId=2030732177 JobName=docker-build-job JobCreationTime=2022-01-29T09:55:15.677Z ArtifactExpirationDate=2022-02-28T09:55:32.861Z"
    "JobId=2030732176 JobName=build-maven3-job JobCreationTime=2022-01-29T09:56:51.158Z ArtifactExpirationDate=2022-02-28T09:57:08.725Z"
    "JobId=2030532173 JobName=docker-build-job JobCreationTime=2022-01-29T09:55:15.677Z ArtifactExpirationDate=2022-02-28T09:55:32.861Z"
    

    Note: The per_page needs to be a really big number in order to retrieve all jobs