Code Studio

Customizing a default Code Studio pipeline

Note

For information about the default .gitlab-ci.yml file used in the Code Studio pipeline, see the standard template.

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 Auto DevOps, 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"

Note

Acquia recommends you to add environment variables through the Code Studio UI. Variables added through the Code Studio UI take higher precedence than variables defined in a .gitlab-ci.yml file. Variables defined in a .gitlab-ci.yml file might not work as expected.

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"

Note

Acquia recommends you to modify environment variables through the Code Studio UI. Variables defined through the Code Studio UI take higher precedence than variables defined in a .gitlab-ci.yml file. Variables defined in a .gitlab-ci.yml file might not work as expected.

Environment variables to enable or disable a CI/CD job

Environment variable name

Description

Default value

ACQUIA_JOBS_TEST_DRUPAL

(affects Test Drupal job)

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

Ensures that the Drupal site is set up when the composer install command is run during the following jobs:

If you enable the Drupal setup, Code Studio runs drush site:install, and imports Drupal configuration if ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT is set to true.

false

ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT

Imports Drupal configuration after the database is created or copied.

This is applicable only when ACQUIA_TASKS_SETUP_DRUPAL is set to true.

true

ACQUIA_JOBS_CREATE_TAG_ARTIFACT

Enables Code Studio to push all tags to Cloud Platform during the Deploy Drupal stage. After Code Studio pushes the tagged release to Cloud Platform, you can select it on any of your Cloud Platform environments.

true

ACQUIA_JOBS_DEPLOY_TAG_ARTIFACT

Deploys the newly created tag to the specified Cloud Platform environment during the Deploy Drupal stage automatically. This variable is applicable only when ACQUIA_JOBS_CREATE_TAG_ARTIFACT is set to true.

To specify the Cloud Platform environment where tags must deploy to, set the ACQUIA_CLOUD_SOURCE_ENVIRONMENT_ID environment variable. If you do not select any environment ID, Code Studio deploys the tags to your production environment.

For more information about enabling deploy tags, see Enabling deploy tags in Code Studio.

false

ACQUIA_TASKS_PHPUNIT

Enables or disables the PHPUnit task during the Test Drupal job of the Auto DevOps pipeline.

When set to true, PHPUnit validates your custom unit tests.

true

ACQUIA_TASKS_PHPCS

Enables or disables the PHP Code Sniffer task during the Test Drupal job of the Auto DevOps pipeline.

When set to true, PHP Code Sniffer validates your custom code to ensure that the code follows established Drupal coding standards.

true

ACQUIA_TASKS_PHPSTAN

Enables or disables the PHPStan task during the Test Drupal job of the Auto DevOps pipeline.

When set to true, PHPStan validates your custom code to ensure that the code does not rely on deprecated functions or services.

true

ACQUIA_TASKS_DRUTINY

Enables or disables the Drutiny task during the Test Drupal job of the Auto DevOps pipeline.

When set to true, Drutiny audits and reports the performance and security best practices.

false

Other environment variables

Environment variable name

Description

Default value

ACQUIA_TASKS_SETUP_DRUPAL_STRATEGY

Determines if Code Studio does either of the following during the Test Drupal stage and the Automatic Updates stage:

  • Installs a new Drupal database based on a selected profile

  • Syncs a database from a Cloud Platform environment

The valid values are install or sync.

  • If you select install, you can assign a Drupal profile using the ACQUIA_TASKS_SETUP_DRUPAL_PROFILE environment variable. If you do not select any profile, Code Studio selects the the minimal profile. If ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT is set to true, Code Studio imports your Drupal configuration to the new database.

  • If you select sync, you can set the ACQUIA_CLOUD_SOURCE_ENVIRONMENT_ID and the ACQUIA_CLOUD_SOURCE_DATABASE_NAME environment variables. If you do not set these environment variables, Code Studio syncs your first production database. If ACQUIA_TASKS_SETUP_DRUPAL_CONFIG_IMPORT is set to true, Code Studio imports your Drupal configuration imports to the database after the database is copied.

install

ACQUIA_TASKS_SETUP_DRUPAL_PROFILE

Specifies the install profile that Code Studio uses to create the Drupal database during the Test Drupal stage and the Automatic Updates stage. This variable is applicable only when ACQUIA_TASKS_SETUP_DRUPAL is set to true, and ACQUIA_TASKS_SETUP_DRUPAL_STRATEGY is set to install.

minimal

SAST_EXCLUDED_PATHS

Excludes vulnerabilities from output based on the paths. This is 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

Fetches the database name at run time. This variable is used when the database name is not found.

null

ACQUIA_CLOUD_SOURCE_ENVIRONMENT_ID

Fetches the environment name at run time. This variable is used when an environment ID variable is not found.

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

Fetches the PHP version that the project is running. The valid values are 8.1 and 8.2. This is a mandatory variable.

null

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. Front-end dependencies include final front-end asset files, such as minified .css and .js files. You can build front-end dependencies it in many ways. 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"
]

Ensure that you add the path to your custom theme in the installer-paths key of the composer.json file. For an example, see drupal-recommended-project.

Changing the Node.js version

Code Studio supports the following Node.js versions to build Drupal applications:

  • v18.17.1

  • v20.5.1

The default version is 18.17.1.

To view or change your Node.js version, you must add or update the before_script section in your custom .gitlab-ci.yml file:

  • To view the available versions, add:

    nvm ls
    
  • To switch to a different Node.js version, add:

    nvm use <version_number>
    

    Replace <version_number> with the required version.

  • To view the current Node.js version, add:

    node -v
    

For example:

include:
  - project: 'acquia/standard-template'
    file:
      - '/gitlab-ci/Auto-DevOps.acquia.gitlab-ci.yml'
"Build Drupal":
  before_script:
    - nvm ls
    - nvm use 20.8.0
    - node -v