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/#designated-technical-writers
---
# GitLab Composer Repository
# Composer packages in the Package Registry
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/15886) in [GitLab Premium](https://about.gitlab.com/pricing/) 13.2.
> - [Moved](https://gitlab.com/gitlab-org/gitlab/-/issues/221259) to GitLab Core in 13.3.
With the GitLab Composer Repository, every project can have its own space to store [Composer](https://getcomposer.org/) packages.
Publish [Composer](https://getcomposer.org/) packages in your project's Package Registry.
Then, install the packages whenever you need to use them as a dependency.
## Enabling the Composer Repository
## Create a Composer package
NOTE: **Note:**
This option is available only if your GitLab administrator has
[enabled support for the Package Registry](../../../administration/packages/index.md).
If you do not have a Composer package, create one and check it in to
a repository. This example shows a GitLab repository, but the repository
can be any public or private repository.
When the Composer Repository is enabled, it is available for all new projects
by default. To enable it for existing projects, or if you want to disable it:
1. Create a directory called `my-composer-package` and change to that directory:
1. Navigate to your project's **Settings > General > Visibility, project features, permissions**.
1. Find the Packages feature and enable or disable it.
1. Click on **Save changes** for the changes to take effect.
Publish a Composer package to the Package Registry,
so that anyone who can access the project can use the package as a dependency.
Now that the basics of our project is completed, we can publish the package.
To publish the package, you need:
Prerequisites:
- A personal access token or `CI_JOB_TOKEN`.
- A package in a GitLab repository.
- The project ID, which is on the project's home page.
- A [personal access token](../../../user/profile/personal_access_tokens.md) with the scope set to `api`.
([Deploy tokens](./../../project/deploy_tokens/index.md) are not yet supported for use with Composer.)
NOTE: **Note:**
[Deploy tokens](./../../project/deploy_tokens/index.md) are
[not yet supported](https://gitlab.com/gitlab-org/gitlab/-/issues/240897) for use with Composer.
- Your project ID which can be found on the home page of your project.
To publish the package:
To publish the package hosted on GitLab, make a `POST` request to the GitLab package API.
A tool like `curl` can be used to make this request:
- Send a `POST` request to the [Packages API](../../../api/packages.md).
You can generate a [personal access token](../../../user/profile/personal_access_tokens.md) with the scope set to `api` for repository authentication. For example:
-`<personal-access-token>` is your personal access token.
-`<project_id>` is your project ID.
-`<tag>` is the Git tag name of the version you want to publish.
To publish a branch, use `branch=<branch>` instead of `tag=<tag>`.
-`<personal-access-token>` is your personal access token.
-`<project_id>` is your project ID.
-`<tag>` is the Git tag name of the version you want to publish. In this example it should be `v1.0.0`. Notice that instead of `tag=<tag>` you can also use `branch=<branch>` to publish branches.
You can view the published package by going to **Packages & Registries > Package Registry** and
selecting the **Composer** tab.
If the above command succeeds, you now should be able to see the package under the **Packages & Registries** section of your project page.
## Publish a Composer package by using CI/CD
### Publishing the package with CI/CD
You can publish a Composer package to the Package Registry as part of your CI/CD process.
To work with Composer commands within [GitLab CI/CD](./../../../ci/README.md), you can
publish Composer packages by using `CI_JOB_TOKEN` in your `.gitlab-ci.yml` file:
1. Specify a `CI_JOB_TOKEN` in your `.gitlab-ci.yml` file:
You can view the published package by going to **Packages & Registries > Package Registry** and selecting the **Composer** tab.
### Use a CI/CD template
### Installing a package
A more detailed Composer CI/CD file is also available as a `.gitlab-ci.yml` template:
To install your package, you need:
1. On the left sidebar, click **Project overview**.
1. Above the file list, click **Set up CI/CD**. If this button is not available, select **CI/CD Configuration** and then **Edit**.
1. From the **Apply a template** list, select **Composer**.
- A personal access token. You can generate a [personal access token](../../../user/profile/personal_access_tokens.md) with the scope set to `api` for repository authentication.
- Your group ID which can be found on the home page of your project's group.
CAUTION: **Warning:**
Do not save unless you want to overwrite the existing CI/CD file.
Add the GitLab Composer package repository to your existing project's `composer.json` file, along with the package name and version you want to install like so:
## Install a Composer package
```json
{
Install a package from the Package Registry so you can use it as a dependency.
Prerequisites:
- A package in the Package Registry.
- The group ID, which is on the group's home page.
- A [personal access token](../../../user/profile/personal_access_tokens.md) with the scope set to `api`.
NOTE: **Note:**
[Deploy tokens](./../../project/deploy_tokens/index.md) are
[not yet supported](https://gitlab.com/gitlab-org/gitlab/-/issues/240897) for use with Composer.
To install a package:
1. Add the Package Registry URL to your project's `composer.json` file, along with the package name and version you want to install:
If successful, you should be able to see the output indicating that the package has been successfully installed.
Output indicates that the package has been successfully installed.
CAUTION: **Important:**
Make sure to never commit the `auth.json` file to your repository. To install packages from a CI job,
Never commit the `auth.json` file to your repository. To install packages from a CI/CD job,
consider using the [`composer config`](https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md#authentication) tool with your personal access token
stored in a [GitLab CI/CD environment variable](../../../ci/variables/README.md) or in
@@ -31,7 +31,7 @@ authenticate with GitLab by using the `CI_JOB_TOKEN`.
CI/CD templates, which you can use to get started, are in [this repo](https://gitlab.com/gitlab-org/gitlab/-/tree/master/lib/gitlab/ci/templates).
Learn more about [using CI/CD to build Maven packages](../maven_repository/index.md#creating-maven-packages-with-gitlab-cicd), [NPM packages](../npm_registry/index.md#publishing-a-package-with-cicd), [Composer packages](../composer_repository/index.md#publishing-the-package-with-cicd), [NuGet Packages](../nuget_repository/index.md#publishing-a-nuget-package-with-cicd), [Conan Packages](../conan_repository/index.md#using-gitlab-ci-with-conan-packages), and [PyPI packages](../pypi_repository/index.md#using-gitlab-ci-with-pypi-packages).
Learn more about [using CI/CD to build Maven packages](../maven_repository/index.md#creating-maven-packages-with-gitlab-cicd), [NPM packages](../npm_registry/index.md#publishing-a-package-with-cicd), [Composer packages](../composer_repository/index.md#publish-a-composer-package-by-using-cicd), [NuGet Packages](../nuget_repository/index.md#publishing-a-nuget-package-with-cicd), [Conan Packages](../conan_repository/index.md#using-gitlab-ci-with-conan-packages), and [PyPI packages](../pypi_repository/index.md#using-gitlab-ci-with-pypi-packages).
If you use CI/CD to build a package, extended activity
information is displayed when you view the package details: