Using Gitlab CI/CD
By following the guidelines in this section, you can use GitLab CI/CD to automatically build and deploy your project to EdgeOne Makers.
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 obtained from the EdgeOne Makers 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 makers 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 makers deploy -n $PROJECT_NAME -t $EDGEONE_API_TOKEN -e production
Configuration Instructions
EdgeOne CLI Deployment Command
npx edgeone makers deploy -n <project-name> -t <API_TOKEN> -e <environment>
Parameter | Description |
-n <project name> | EdgeOne Makers project name. If the project does not exist, it will be created automatically. |
-t <API_TOKEN> | EdgeOne Makers 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 a successful deployment, access the EdgeOne Makers console to view the deployed project and its access URL.
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: Specify the name of an existing project using the
-n parameter in the deployment command, and the deployment for that project will be updated automatically.