Using Gitlab CI/CD
With this section guide, you can use GitLab CI/CD for automated build and deploy project to EdgeOne Pages.
Configure GitLab CI/CD Variables
1. Enter the GitLab warehouse page, click in the left menu Settings > CI/CD.
2. Unfold the Variables part and click Add variable.
3. Configure the following variables:
Key:
EDGEONE_API_TOKENValue: API Token retrieved from EdgeOne Pages console
Type: Variable
Flags: Check Mask variable (hide variable value) and Protect variable (Option, only for protected branch usage)
Create a GitLab CI/CD Configuration File
Create a file named
.gitlab-ci.yml in the root directory of your GitLab repository and add the following content:stages:- deployvariables:PROJECT_NAME: "my-project" # change to your project name# Cache node_modules to speed up builds (Option)cache:key: ${CI_COMMIT_REF_SLUG}paths:- node_modules/# Scenario 1: Deploy preview URL before code merge (Preview)# Trigger when a Merge Request is generateddeploy-preview:image: node:22.11.0 # Select a suitable Node.js versionstage: deployonly:- merge_requestsscript:- npm install- npm run build- npx edgeone pages deploy -n $PROJECT_NAME -t $EDGEONE_API_TOKEN -e preview# Scenario 2: Deploy trunk code change (Production)# Trigger when code is pushed to the main branchdeploy-production:image: node:22.11.0 # Select a suitable Node.js versionstage: deployonly:- mainscript:- npm install- npm run build- npx edgeone pages deploy -n $PROJECT_NAME -t $EDGEONE_API_TOKEN -e production
Configuration Instructions
EdgeOne CLI Deployment Command
npx edgeone pages deploy -n <project name> -t <API_TOKEN> -e <environment>
Parameter | Description |
-n <project name> | EdgeOne Pages project name. If the project does not exist, it will automatically create one. |
-t <API_TOKEN> | EdgeOne Pages API Token |
-e <environment> | Deployment environment, selectable preview (Preview) or production (Production) |
Deployment Scenario Description
Scenario | Trigger Condition | Environment Parameter | Description |
preview deployment | Merge Request | -e preview | Each time an MR is generated, an independent preview URL is created for code review to view the effect |
production deployment | push to the main branch | -e production | After code merge, automatic deployment to the production environment is used for official release, with high traffic and stability requirements. |
Workflow
After the configuration is complete, GitLab CI/CD will automatically execute the following process:
Preview Environment (Merge Request)
1. Trigger Condition: Automatically trigger when creating or updating a Merge Request.
2. Execution Process: Dependency installation → Build project → Deploy to preview environment
3. Result: Generate a preview URL, which can be viewed in the MR to see the effect.
Production Environment (Main Branch)
1. Trigger Condition: Automatically trigger when code is pushed to the main branch.
2. Execution Process: Dependency installation → Build project → Deploy to production environment
3. Result: Update the production environment site
View Deployment Result
1. On the GitLab warehouse page, click Build > Pipelines in the left menu to view the pipeline status.
2. Click on the pipeline to view stage execution details.
3. After successful deployment, access the EdgeOne Pages console to view the deployed project and access domain.
FAQs
Q: Pipeline Execution Failed with a Permission Error Notification?
A: Please check whether the
EDGEONE_API_TOKEN variable is configured correctly and ensure the TOKEN is not expired.Q: How to Deploy to an Existing Project?
A: Just specify the existing project name with the
-n parameter in the deployment command, and EdgeOne Pages will auto-update the project deployment.