2020-10-13 00:08:42 +00:00
---
stage: Package
group: Package
2020-11-26 06:09:20 +00:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-10-13 00:08:42 +00:00
---
2021-01-28 06:08:59 +00:00
# GitLab Generic Packages Repository **(FREE)**
2020-10-13 00:08:42 +00:00
2022-02-18 12:15:31 +00:00
> - [Introduced](https://gitlab.com/groups/gitlab-org/-/epics/4209) in GitLab 13.5 [with a flag](../../../administration/feature_flags.md) named `generic_packages`. Enabled by default.
2022-03-01 18:20:20 +00:00
> - [Feature flag `generic_packages`](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/80886) removed in GitLab 14.8.
2020-10-13 00:08:42 +00:00
2021-03-17 15:09:03 +00:00
Publish generic files, like release binaries, in your project's Package Registry. Then, install the packages whenever you need to use them as a dependency.
2020-10-13 00:08:42 +00:00
## Authenticate to the Package Registry
2022-01-17 12:17:11 +00:00
To authenticate to the Package Registry, you need either a [personal access token ](../../../api/index.md#personalprojectgroup-access-tokens ),
2021-09-03 18:10:36 +00:00
[CI/CD job token ](../../../ci/jobs/ci_job_token.md ), or [deploy token ](../../project/deploy_tokens/index.md ).
2021-01-08 12:10:35 +00:00
In addition to the standard API authentication mechanisms, the generic package
API allows authentication with HTTP Basic authentication for use with tools that
do not support the other available mechanisms. The `user-id` is not checked and
2022-01-17 12:17:11 +00:00
may be any value, and the `password` must be either a [personal access token ](../../../api/index.md#personalprojectgroup-access-tokens ),
2021-09-03 18:10:36 +00:00
a [CI/CD job token ](../../../ci/jobs/ci_job_token.md ), or a [deploy token ](../../project/deploy_tokens/index.md ).
2020-10-13 00:08:42 +00:00
## Publish a package file
When you publish a package file, if the package does not exist, it is created.
Prerequisites:
2021-11-05 00:13:17 +00:00
- You must [authenticate with the API ](../../../api/index.md#authentication ).
If authenticating with a deploy token, it must be configured with the `write_package_registry`
scope. If authenticating with a personal access token or project access token, it must be
configured with the `api` scope.
2022-05-20 00:08:57 +00:00
- You must call this API endpoint serially when attempting to upload multiple files under the
same package name and version. Attempts to concurrently upload multiple files into
a new package name and version may face partial failures with
`HTTP 500: Internal Server Error` responses due to the requests racing to
create the package.
2020-10-13 00:08:42 +00:00
```plaintext
2021-03-03 18:11:16 +00:00
PUT /projects/:id/packages/generic/:package_name/:package_version/:file_name?status=:status
2020-10-13 00:08:42 +00:00
```
| Attribute | Type | Required | Description |
| -------------------| --------------- | ---------| -------------------------------------------------------------------------------------------------------------------------------- |
2021-06-28 15:08:03 +00:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](../../../api/index.md#namespaced-path-encoding ). |
2020-10-13 00:08:42 +00:00
| `package_name` | string | yes | The package name. It can contain only lowercase letters (`a-z`), uppercase letter (`A-Z`), numbers (`0-9`), dots (`.`), hyphens (`-`), or underscores (`_`).
2021-03-30 15:11:08 +00:00
| `package_version` | string | yes | The package version. The following regex validates this: `\A(\.?[\w\+-]+\.?)+\z` . You can test your version strings on [Rubular ](https://rubular.com/r/aNCV0wG5K14uq8 ).
2021-02-04 09:09:30 +00:00
| `file_name` | string | yes | The filename. It can contain only lowercase letters (`a-z`), uppercase letter (`A-Z`), numbers (`0-9`), dots (`.`), hyphens (`-`), or underscores (`_`).
2021-02-17 12:09:26 +00:00
| `status` | string | no | The package status. It can be `default` (default) or `hidden` . Hidden packages do not appear in the UI or [package API list endpoints ](../../../api/packages.md ).
2021-10-27 00:13:04 +00:00
| `select` | string | no | The response payload. By default, the response is empty. Valid values are: `package_file` . `package_file` returns details of the package file record created by this request.
2020-10-13 00:08:42 +00:00
Provide the file context in the request body.
2021-03-11 21:09:09 +00:00
Example request using a personal access token:
2020-10-13 00:08:42 +00:00
```shell
curl --header "PRIVATE-TOKEN: < your_access_token > " \
--upload-file path/to/file.txt \
2022-02-12 00:12:46 +00:00
"https://gitlab.example.com/api/v4/projects/24/packages/generic/my_package/0.0.1/file.txt"
2020-10-13 00:08:42 +00:00
```
2021-10-27 00:13:04 +00:00
Example response without attribute `select` :
2020-10-13 00:08:42 +00:00
```json
{
"message":"201 Created"
}
```
2022-05-25 15:08:05 +00:00
Example request with attribute `select = package_file` :
```shell
curl --header "PRIVATE-TOKEN: < your_access_token > " \
--upload-file path/to/file.txt \
"https://gitlab.example.com/api/v4/projects/24/packages/generic/my_package/0.0.1/file.txt?select=package_file"
```
2021-10-27 00:13:04 +00:00
Example response with attribute `select = package_file` :
```json
{
"id": 1,
"package_id": 1,
"created_at": "2021-10-12T12:05:23.387Z",
"updated_at": "2021-10-12T12:05:23.387Z",
"size": 0,
"file_store": 1,
"file_md5": null,
"file_sha1": null,
"file_name": "file.txt",
"file": {
"url": "/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b/packages/26/files/36/file.txt"
},
"file_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"verification_retry_at": null,
"verified_at": null,
"verification_failure": null,
"verification_retry_count": null,
"verification_checksum": null,
"verification_state": 0,
"verification_started_at": null,
"new_file_path": null
}
```
2021-08-05 18:10:13 +00:00
### Publishing a package with the same name or version
When you publish a package with the same name and version as an existing package, the new package
files are added to the existing package. You can still use the UI or API to access and view the
existing package's older files. To delete these older package revisions, consider using the Packages
API or the UI.
#### Do not allow duplicate Generic packages
2022-05-11 12:09:03 +00:00
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/293755) in GitLab 13.12.
> - [Required permissions](https://gitlab.com/gitlab-org/gitlab/-/issues/350682) changed from developer to maintainer in GitLab 15.0.
2021-08-05 18:10:13 +00:00
To prevent users from publishing duplicate generic packages, you can use the [GraphQl API ](../../../api/graphql/reference/index.md#packagesettings )
or the UI.
In the UI:
1. For your group, go to **Settings > Packages & Registries** .
1. Expand the **Package Registry** section.
1. Turn on the **Reject duplicates** toggle.
1. Optional. To allow some duplicate packages, in the **Exceptions** box enter a regex pattern that
matches the names and/or versions of packages to allow.
Your changes are automatically saved.
2020-10-13 00:08:42 +00:00
## Download package file
2020-12-22 18:10:05 +00:00
Download a package file.
If multiple packages have the same name, version, and filename, then the most recent one is retrieved.
2020-10-13 00:08:42 +00:00
Prerequisites:
2021-06-28 15:08:03 +00:00
- You need to [authenticate with the API ](../../../api/index.md#authentication ). If authenticating with a deploy token, it must be configured with the `read_package_registry` and/or `write_package_registry` scope.
2020-10-13 00:08:42 +00:00
```plaintext
GET /projects/:id/packages/generic/:package_name/:package_version/:file_name
```
| Attribute | Type | Required | Description |
| -------------------| --------------- | ---------| ------------------------------------------------------------------------------------|
2021-06-28 15:08:03 +00:00
| `id` | integer/string | yes | The ID or [URL-encoded path of the project ](../../../api/index.md#namespaced-path-encoding ). |
2020-10-13 00:08:42 +00:00
| `package_name` | string | yes | The package name. |
| `package_version` | string | yes | The package version. |
2021-02-04 09:09:30 +00:00
| `file_name` | string | yes | The filename. |
2020-10-13 00:08:42 +00:00
2020-11-25 18:09:53 +00:00
The file context is served in the response body. The response content type is `application/octet-stream` .
2020-10-13 00:08:42 +00:00
Example request that uses a personal access token:
```shell
curl --header "PRIVATE-TOKEN: < your_access_token > " \
2020-12-09 06:09:41 +00:00
"https://gitlab.example.com/api/v4/projects/24/packages/generic/my_package/0.0.1/file.txt"
2020-10-13 00:08:42 +00:00
```
2021-01-08 12:10:35 +00:00
Example request that uses HTTP Basic authentication:
```shell
curl --user "user:< your_access_token > " \
2021-09-08 09:09:10 +00:00
"https://gitlab.example.com/api/v4/projects/24/packages/generic/my_package/0.0.1/file.txt"
2021-01-08 12:10:35 +00:00
```
2020-10-13 00:08:42 +00:00
## Publish a generic package by using CI/CD
2021-06-28 15:08:03 +00:00
To work with generic packages in [GitLab CI/CD ](../../../ci/index.md ), you can use
2020-10-13 00:08:42 +00:00
`CI_JOB_TOKEN` in place of the personal access token in your commands.
For example:
```yaml
image: curlimages/curl:latest
stages:
- upload
- download
upload:
stage: upload
script:
2020-12-09 06:09:41 +00:00
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file path/to/file.txt "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/my_package/0.0.1/file.txt"'
2020-10-13 00:08:42 +00:00
download:
stage: download
script:
- 'wget --header="JOB-TOKEN: $CI_JOB_TOKEN" ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/my_package/0.0.1/file.txt'
```
2021-07-29 21:10:10 +00:00
When using a Windows runner with PowerShell, you must use `Invoke-WebRequest` or `Invoke-RestMethod`
instead of `curl` in the `upload` and `download` stages.
For example:
```yaml
upload:
stage: upload
script:
- Invoke-RestMethod -Headers @{ "JOB-TOKEN"="$CI_JOB_TOKEN" } -InFile path/to/file.txt -uri "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/my_package/0.0.1/file.txt" -Method put
```
2020-11-04 03:09:14 +00:00
### Generic package sample project
The [Write CI-CD Variables in Pipeline ](https://gitlab.com/guided-explorations/cfg-data/write-ci-cd-variables-in-pipeline ) project contains a working example you can use to create, upload, and download generic packages in GitLab CI/CD.
It also demonstrates how to manage a semantic version for the generic package: storing it in a CI/CD variable, retrieving it, incrementing it, and writing it back to the CI/CD variable when tests for the download work correctly.
2022-07-14 15:08:22 +00:00
## Troubleshooting
### Internal Server error on large file uploads to S3
S3-compatible object storage [limits the size of a single PUT request to 5GB ](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html ). If the `aws_signature_version` is set to `2` in the [object storage connection settings ](../../../administration/object_storage.md ), attempting to publish a package file larger than the 5GB limit can result in a `HTTP 500: Internal Server Error` response.
If you are receiving `HTTP 500: Internal Server Error` responses when publishing large files to S3, set the `aws_signature_version` to `4` :
```ruby
# Consolidated Object Storage settings
gitlab_rails['object_store']['connection'] = {
# Other connection settings
`aws_signature_version` => '4'
}
# OR
# Storage-specific form settings
gitlab_rails['packages_object_store_connection'] = {
# Other connection settings
`aws_signature_version` => '4'
}
```