相关文章推荐
卖萌的烤土司  ·  BadRequestObjectResult ...·  7 月前    · 
坏坏的板栗  ·  java对cron计算处理 - ...·  1 年前    · 
  • Download the artifacts archive
  • Download a single artifact file by job ID
  • Download a single artifact file from specific tag or branch
  • Keep artifacts
  • Delete job artifacts
  • Delete project artifacts

    Job Artifacts API Tier: Free, Premium, Ultimate Offering: GitLab.com, Self-managed, GitLab Dedicated

    Use the job artifacts API to download or delete job artifacts.

    Authentication with a CI/CD job token available in the Premium and Ultimate tier.

    Get job artifacts History
  • The use of CI_JOB_TOKEN in the artifacts download API was introduced in GitLab Premium 9.5.

    Get the job’s artifacts zipped archive of a project.

    If you use cURL to download artifacts from GitLab.com, use the --location parameter as the request might redirect through a CDN.

    GET /projects/:id/jobs/:job_id/artifacts
    string
    To be used with triggers for multi-project pipelines. It should be invoked only in a CI/CD job defined in the .gitlab-ci.yml file. The value is always $CI_JOB_TOKEN. The job associated with the $CI_JOB_TOKEN must be running when this token is used. Premium and Ultimate only.
    

    Example request using the PRIVATE-TOKEN header:

    curl --location --output artifacts.zip --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts"
    

    In the Premium and Ultimate tier you can authenticate with this endpoint in a CI/CD job by using a CI/CD job token.

    Use either:

    The job_token attribute with the GitLab-provided CI_JOB_TOKEN predefined variable. For example, the following job downloads the artifacts of the job with ID 42:

    artifact_download:
      stage: test
      script:
        - 'curl --location --output artifacts.zip "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts?job_token=$CI_JOB_TOKEN"'
    

    The JOB-TOKEN header with the GitLab-provided CI_JOB_TOKEN predefined variable. For example, the following job downloads the artifacts of the job with ID 42. The command is wrapped in single quotes because it contains a colon (:):

    artifact_download:
      stage: test
      script:
        - 'curl --location --output artifacts.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts"'
    

    Possible response status codes: Status Description Serves the artifacts file. Build not found or no artifacts.

    Download the artifacts archive History
  • The use of CI_JOB_TOKEN in the artifacts download API was introduced in GitLab Premium 9.5.

    Download the artifacts zipped archive from the latest successful pipeline for the given reference name and job, provided the job finished successfully. This is the same as getting the job’s artifacts, but by defining the job’s name instead of its ID.

    If you use cURL to download artifacts from GitLab.com, use the --location parameter as the request might redirect through a CDN. note

    If a pipeline is parent of other child pipelines, artifacts are searched in hierarchical order from parent to child. For example, if both parent and child pipelines have a job with the same name, the artifact from the parent pipeline is returned.
    GET /projects/:id/jobs/artifacts/:ref_name/download?job=name
    

    Parameters Attribute Required Description integer/string ID or URL-encoded path of the project. string The name of the job. ref_name string Branch or tag name in repository. HEAD or SHA references are not supported. job_token string To be used with triggers for multi-project pipelines. It should be invoked only in a CI/CD job defined in the .gitlab-ci.yml file. The value is always $CI_JOB_TOKEN. The job associated with the $CI_JOB_TOKEN must be running when this token is used. Premium and Ultimate only.

    Example request using the PRIVATE-TOKEN header:

    curl --location --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/main/download?job=test"
    

    In the Premium and Ultimate tier you can authenticate with this endpoint in a CI/CD job by using a CI/CD job token.

    Use either:

    The job_token attribute with the GitLab-provided CI_JOB_TOKEN predefined variable. For example, the following job downloads the artifacts of the test job of the main branch:

    artifact_download:
      stage: test
      script:
        - 'curl --location --output artifacts.zip "https://gitlab.example.com/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/main/download?job=test&job_token=$CI_JOB_TOKEN"'
    

    The JOB-TOKEN header with the GitLab-provided CI_JOB_TOKEN predefined variable. For example, the following job downloads the artifacts of the test job of the main branch. The command is wrapped in single quotes because it contains a colon (:):

    artifact_download:
      stage: test
      script:
        - 'curl --location --output artifacts.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.example.com/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/main/download?job=test"'
    

    Possible response status codes: Status Description Serves the artifacts file. Build not found or no artifacts.

    Download a single artifact file by job ID

    Download a single artifact file from a job with a specified ID from inside the job’s artifacts zipped archive. The file is extracted from the archive and streamed to the client.

    If you use cURL to download artifacts from GitLab.com, use the --location parameter as the request might redirect through a CDN.

    GET /projects/:id/jobs/:job_id/artifacts/*artifact_path
    

    Parameters Attribute Required Description artifact_path string Path to a file inside the artifacts archive. integer/string ID or URL-encoded path of the project. job_id integer The unique job identifier. job_token string To be used with triggers for multi-project pipelines. It should be invoked only in a CI/CD job defined in the .gitlab-ci.yml file. The value is always $CI_JOB_TOKEN. The job associated with the $CI_JOB_TOKEN must be running when this token is used. Premium and Ultimate only.

    Example request:

    curl --location --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/5/artifacts/some/release/file.pdf"
    

    In the Premium and Ultimate tier you can authenticate with this endpoint in a CI/CD job by using a CI/CD job token.

    Possible response status codes: Status Description Sends a single artifact file Invalid path provided Build not found or no file/artifacts

    Download a single artifact file from specific tag or branch

    Download a single artifact file for a specific job of the latest successful pipeline for the given reference name from inside the job’s artifacts archive. The file is extracted from the archive and streamed to the client, with the plain/text content type.

    The artifact file provides more detail than what is available in the CSV export.

    Artifacts for parent and child pipelines are searched in hierarchical order from parent to child. For example, if both parent and child pipelines have a job with the same name, the artifact from the parent pipeline is returned.

    If you use cURL to download artifacts from GitLab.com, use the --location parameter as the request might redirect through a CDN.

    GET /projects/:id/jobs/artifacts/:ref_name/raw/*artifact_path?job=name
    

    Parameters: Attribute Required Description artifact_path string Path to a file inside the artifacts archive. integer/string ID or URL-encoded path of the project. string The name of the job. ref_name string Branch or tag name in repository. HEAD or SHA references are not supported. job_token string To be used with triggers for multi-project pipelines. It should be invoked only in a CI/CD job defined in the .gitlab-ci.yml file. The value is always $CI_JOB_TOKEN. The job associated with the $CI_JOB_TOKEN must be running when this token is used. Premium and Ultimate only.

    Example request:

    curl --location --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/main/raw/some/release/file.pdf?job=pdf"
    

    In the Premium and Ultimate tier you can authenticate with this endpoint in a CI/CD job by using a CI/CD job token.

    Possible response status codes: Status Description Sends a single artifact file Invalid path provided Build not found or no file/artifacts

    Keep artifacts

    Prevents artifacts from being deleted when expiration is set.

    POST /projects/:id/jobs/:job_id/artifacts/keep
    

    Parameters Attribute Required Description integer/string ID or URL-encoded path of the project owned by the authenticated user. job_id integer ID of a job.

    Example request:

    curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/1/artifacts/keep"
    

    Example response: "commit": { "author_email": "admin@example.com", "author_name": "Administrator", "created_at": "2015-12-24T16:51:14.000+01:00", "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", "message": "Test the CI integration.", "short_id": "0ff3ae19", "title": "Test the CI integration." "coverage": null, "allow_failure": false, "download_url": null, "id": 42, "name": "rubocop", "ref": "main", "artifacts": [], "runner": null, "stage": "test", "created_at": "2016-01-11T10:13:33.506Z", "started_at": "2016-01-11T10:13:33.506Z", "finished_at": "2016-01-11T10:15:10.506Z", "duration": 97.0, "status": "failed", "failure_reason": "script_failure", "tag": false, "web_url": "https://example.com/foo/bar/-/jobs/42", "user": null

    Delete job artifacts

    Delete artifacts of a job.

    Prerequisites:

  • Must have at least the maintainer role in the project.
    DELETE /projects/:id/jobs/:job_id/artifacts
    

    Example request:

    curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/1/artifacts"
    note
    At least Maintainer role is required to delete artifacts.

    If the artifacts were deleted successfully, a response with status 204 No Content is returned.

    Delete project artifacts

    Delete artifacts eligible for deletion in a project. By default, artifacts from the most recent successful pipeline of each ref are not deleted.

    Requests to this endpoint set the expiry of all artifacts that can be deleted to the current time. The files are then deleted from the system as part of the regular cleanup of expired job artifacts. Job logs are never deleted.

    The regular cleanup occurs asynchronously on a schedule, so there might be a short delay before artifacts are deleted.

    Prerequisites:

  • You must have at least the Maintainer role for the project.
    DELETE /projects/:id/artifacts
    

    Example request:

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

    A response with status 202 Accepted is returned. to fix an error or add an improvement in a merge request.
    Create an issue to suggest an improvement to this page.

    Product

    Create an issue if there's something you don't like about this feature.
    Propose functionality by submitting a feature request.
    Join First Look to help shape new features.

    Feature availability and product trials

    View pricing to see all GitLab tiers and features, or to upgrade.
    Try GitLab for free with access to all features for 30 days.
    search the docs.
    If you want help with something specific and could use community support, post on the GitLab forum.
    For problems setting up or using this feature (depending on your GitLab subscription).
    Request support
  •