Information for: DEVELOPERS   PARTNERS   SUPPORT

Customizing a default Code Studio pipeline

To use a custom .gitlab-ci.yml file to customize a default Code Studio pipeline, change the CI/CD configuration file path of the project:

  1. Click Settings > CI/CD.

  2. In the General pipelines section, click Expand and then enter the path to the custom .gitlab-ci.yml file.

  3. Click Save changes.

For any default job run by Code Studio AutoDevOps, you can:

  • Enable or disable the job using an environment variable.

  • Add a before_script to execute your own custom script before the Code Studio script.

  • Replace the default script with your own custom script.

  • Add an after_script to execute your own custom script after the Code Studio script.

Environment variables

The Code Studio pipeline is ready-for-use and out-of-the-box. However, it is also customizable to fit the needs of different projects.

You can use environment variables to:

  • Override default values of the CI/CD pipeline

  • Enable or disable specific jobs

  • Set custom or specific parameters for the CI/CD pipeline

    For example, you can set an environment variable so that the pipeline is aware of the PHP version in your repository.

Adding environment variables

  1. Click Settings > CI/CD.

  2. In the Variables section, click Expand and then click Add variable.

  3. In the Add variable dialog box, specify the appropriate value in each field.

  4. Click Add variable.

You can also add environment variables through the .gitlab-ci.yml file.

For example:

include:
  - project: 'acquia/standard-template'
    file:
     - '/gitlab-ci/Auto-DevOps.acquia.gitlab-ci.yml'
variables:
  - ACQUIA_JOBS_CREATE_CDE: "true"

Modifying environment variables

  1. Click Settings > CI/CD.

  2. In the Variables section, click Expand and then click the pencil icon next to the environment variable that you want to edit.

  3. In the Update variable dialog box, change the value of the environment variable.

  4. Click Update variable.

You can also edit environment variables through the .gitlab-ci.yml file.

For example:

include:
  - project: 'acquia/standard-template'
    file:
     - '/gitlab-ci/Auto-DevOps.acquia.gitlab-ci.yml'
variables:
  - ACQUIA_JOBS_CREATE_CDE: "false"

Environment variables to enable or disable a CI/CD job

Environment variable name

Description

Default value

ACQUIA_JOBS_BUILD_DRUPAL

Enables or disables the Build Code job of the Auto DevOps pipeline.

When set to true, the Build Code and Manage Secrets jobs execute.

true

ACQUIA_JOBS_TEST_DRUPAL

(affects both BLT Test Drupal and Test Drupal jobs)

Enables or disables the Test Drupal stage of the Auto DevOps pipeline.

When set to true, the Test Drupal job executes.

true

ACQUIA_JOBS_CREATE_CDE

Enables or disables the Acquia Continuous Delivery Environment (CDE) creation during the Deploy Drupal stage.

When set to true, this creates an Acquia CDE during the merge process for Automatic Updates.

Note

  • You must have an Acquia Cloud CD entitlement for this feature to work with Code Studio.

  • Site Factory does not support CDEs. Set this variable to false when using a Site Factory application with Code Studio.

true

ACQUIA_JOBS_DEPRECATED_UPDATE

Enables or disables the Deprecated Code Update job of Automatic Updates.

When set to true, the Deprecated Code Update job runs at the scheduled time.

true

ACQUIA_JOBS_COMPOSER_UPDATE

Enables or disables the Composer Update job of Automatic Updates.

When set to true, the Composer Update job runs at the scheduled time.

true

ACQUIA_JOBS_VALIDATE_CODE

Enables or disables the Validate Code Structure job of the Auto DevOps pipeline.

When set to true, the Validate Code Structure job executes.

true

ACQUIA_TASKS_SETUP_DRUPAL

Enables Drupal setup upon Composer install during the following jobs:

true

ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT

Performs config import using drush config:import.

It is effective if ACQUIA_TASKS_SETUP_DRUPAL is set to true.

true

ACQUIA_JOBS_CREATE_TAG_ARTIFACT

Creates or reflects a tagged release made in Code Studio on Cloud Platform as part of the Create artifact from tag job under the Deploy Drupal stage.

true

ACQUIA_JOBS_DEPLOY_TAG_ARTIFACT

When set to true, this job automates the tag creation process during deployment to the production environment in Cloud Platform under the Deploy Drupal stage.

For more information on how to enable deploy tags, see Enabling deploy tags in Code Studio.

false

Other environment variables

Environment variable name

Description

Default value

ACQUIA_TASKS_SETUP_DRUPAL_STRATEGY

Determines if Code Studio installs a clean version of Drupal using an install profile that ACQUIA_TASKS_SETUP_DRUPAL_PROFILE configures, or syncs a database from a cloud environment using ACQUIA_CLOUD_SOURCE_ENVIRONMENT_ID.

This variable also syncs drush cache:rebuild and import config.

install, sync

ACQUIA_TASKS_SETUP_DRUPAL_PROFILE

The name of the Drupal profile used during drush site:install.

If ACQUIA_TASKS_SETUP_DRUPAL is set to true, Code Studio executes drush site:install and uses the install profile that ACQUIA_TASKS_SETUP_DRUPAL_PROFILE configures. If this variable is not configured manually, its default value is set to the minimal profile.

minimal

SAST_EXCLUDED_PATHS

A vulnerability filter from GitLab.

All Acquia-managed SAST scan jobs for Drupal run as part of the Test Drupal stage of the Auto DevOps pipeline.

spec, test, tests, tmp, node_modules, vendor, contrib, core

ACQUIA_CLOUD_SOURCE_DATABASE_NAME

Used when the database name is not found. Code Studio fetches the database name at run time.

null

ACQUIA_CLOUD_SOURCE_ENVIRONMENT_ID

Used when an environment ID variable is not found. Code Studio fetches the environment name at run time.

To automatically deploy tags to an environment other than production, set the variable to the environment ID of your target environment. For more information, see Deploy Drupal stage.

null

PHP_VERSION

The PHP version that the project is running. The valid values are 8.0, 8.1, and 8.2.

8.0

Adding a before_script or after_script to a Code Studio job

include:
  - project: 'acquia/standard-template'
    file:
      - '/gitlab-ci/Auto-DevOps.acquia.gitlab-ci.yml'
"Test Drupal":
  before_script:
    - echo “Hello world!”

Building front-end dependencies

A common use case for customizing a job is to build front-end dependencies. You can do it in many ways. For example, you can:

  • Add a post-install-cmd to your composer.json file.

  • Create a custom Composer script named build-theme and call it during a CI/CD job.

Composer post-install-cmd

A quick way to build front-end dependencies is to add post-install-cmd to your project’s composer.json file. The post-install-cmd must contain the commands that must be executed to build your front-end dependencies.

For example, in composer.json:

"post-install-cmd": [
 "cd docroot/themes/custom/<my_theme> && rm -rf node_modules && npm install && npm run build"
]

Custom Composer script

An advantage of wrapping your commands in a Composer script is that you can easily run the command during a job, and also within your IDE.

For example, in composer.json:

"scripts": {
  "build-theme": ["cd docroot/themes/custom/<my_theme> && rm -rf node_modules && npm install && npm run build"]
}

For example, in .gitlab-ci.yml:

"Test Drupal":
  before_script:
    - composer run-script build-theme

In this example, the front-end theme is built before the Test Drupal job, and will be included in the artifact pushed to Acquia Cloud.

When you need to build theme dependencies, you can run composer run-script build-theme in an IDE.

Using BLT with Code Studio

Code Studio is built to easily integrate with BLT (Build and Launch Tool). Using both tools, you can quickly have an advanced, comprehensive Drupal CI/CD workflow running in a couple of minutes.

  1. Run the following command to add BLT:

    composer require acquia/blt
    
  2. In blt/blt.yml, place your Cloud Platform application Git URL in the git.remotes array, and then disable the Git hooks:

    git:
        remotes:
            - [email protected]:foo.git
        hooks:
            pre-commit: false
            pre-push: false
            commit-msg: false
    
  3. Commit and push your changes.

    Code Studio now uses BLT in AutoDev Ops.