Skip to content

GitLab CI CD Pipeline

Alexander Lukyanov edited this page Apr 29, 2022 · 5 revisions

Before You Get Started

  1. Review the Pipeline Configuration

Enable GitLab CI/CD and Add Variables

Enable GitLab CI/CD Pipelines

To enable or disable GitLab CI/CD pipelines in your project:

  • On the top bar, select Menu > Projects and find your project.
  • On the left sidebar, select Settings > General.
  • Expand Visibility, project features, permissions.
  • In the Repository section, turn on or off CI/CD as required.

Press Save changes for the settings to take effect.

Add Variables

Add at least two variables: MAGENTO_USER and MAGENTO_PASS. These would be Magento composer keys that can be generated at Magento Commerce Marketplace

  1. Go to your project’s Settings > CI/CD and expand the Variables section.
  2. Select the Add Variable button and fill in the details:

An Example:

  • Key: MAGENTO_USER
  • Value: {key}
  • Type: Variable.
  • Environment scope: All
  • Protect variable: Yes
  • Mask variable: Yes

Additional Repository Variables (Optional)

You may need to add more variables in the case where you use a 3rd party modules that require composer authentication. In the most cases you will have these keys at the auth.json file in your Magento 2 root folder. After you add a custom variables you will need to make changes to a pipeline YML File.

More information


Pipeline For a Composer Module

To setup pipeline:

  1. Copy the example YML file: https://github.com/sashas777/magento-docker-pipelines/blob/master/pipelines/GitLab_CI/composer_module.gitlab-ci.yml to the repository root.
  2. Rename it to .gitlab-ci.yml
  3. Make changes if necessary (Changes To The YML File)

Changes To The YML File

There are multiple changes that may apply for a pipeline.

Pipeline triggers

The each pipeline triggers build after commit to the repository. This can be changed based on the official documentation:

Example only on master branch:

...
install:
    stage: build
    only:
        - master # Limit this job to the master branch
    cache:
....

Add a 3rd Party Composer Credentials

When you use a 3rd party composer module with a custom credentials you will need to add a new line to the bitbucket-pipelines.yml file.

  1. Find a line composer config --global http-basic.repo.magento.com $MAGENTO_USER $MAGENTO_PASS
  2. Duplicate the line
  3. Change variables and composer URL

For example repository variables were CUSTOM_USER and CUSTOM_PASS and a 3rd party composer URL is repo.custom.com:

....
cache:
    key: $CI_COMMIT_SHA
    paths:
        - vendor/
        - composer.lock
script:
    - composer config --global http-basic.repo.magento.com $COMPOSER_USER $COMPOSER_PASSWORD
    - composer config --global http-basic.repo.custom.com $CUSTOM_USER $CUSTOM_PASS --- The new line with a new keys
    - composer require --dev thesgroup/magento2-testing-framework --no-update
    - composer install --no-scripts --no-suggest --no-ansi --no-interaction --no-progress
....
 

NOTE: In the case where your pipeline have multiple lines: composer config --global http-basic.repo.magento.com $MAGENTO_USER $MAGENTO_PASS then you will need to add a 3rd party config after the each line.

PHP Version

The PHP image version can be changed at the line:

image: sashas777/magento-php:7.4-cli
Clone this wiki locally