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:
- Click Settings > CI/CD.
- In the General pipelines section, click Expand and then enter the path to the custom
.gitlab-ci.yml
file. - 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
- Click Settings > CI/CD.
- In the Variables section, click Expand and then click Add variable.
- In the Add variable dialog box, specify the appropriate value in each field.
- 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
- Click Settings > CI/CD.
- In the Variables section, click Expand and then click the pencil icon next to the environment variable that you want to edit.
- In the Update variable dialog box, change the value of the environment variable.
- To configure the environment variables for enabling or disabling a CI/CD job, see Environment variables to enable or disable a CI/CD job.
- To configure other environment variables, see Other environment variables.
- 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
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 for Drupal
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.