本文将指导您如何在 GitLab 中设置 CI/CD pipeline。
前言
Be sure you have added your Capacitor app first to Capgo, this tutorial just focuses on the upload phase. If you need to add your app to Capgo, you can follow this 教程.
提交约定
首先,您需要遵循提交约定 本地构建规范提交

GitLab CI/CD for Tag
在您的 GitLab 仓库根目录下创建一个 .gitlab-ci.yml 文件,并将以下内容添加进去
stages:
- tag
bump_version:
stage: tag
only:
- main
except:
variables:
- $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
script:
- git config --global user.email "gitlab@yourdomain.com"
- git config --global user.name "GitLab CI/CD"
- git checkout $CI_COMMIT_REF_NAME
- git pull origin $CI_COMMIT_REF_NAME
- npx capacitor-standard-version
- git push origin $CI_COMMIT_REF_NAME --tags
替换 "gitlab@yourdomain.com在脚本部分中,使用您的GitLab邮箱和用户名配置“”和“GitLab CI/CD”。此配置仅在推送主分支时触发作业,并排除以“chore(release):”开头的提交消息。
GitLab CI/CD for Build
在 .gitlab-ci.yml 文件中添加另一个阶段:
stages:
- deploy
deploy:
stage: deploy
only:
- tags # This job will only run for tag pushes
script:
- apt-get update -qy && apt-get install -y nodejs npm
- npm install -g @capgo/cli
- npm ci
- npm run build
- npx @capgo/cli bundle upload -a $CAPGO_TOKEN -c production
variables:
FIREBASE_CONFIG: $FIREBASE_CONFIG # Define this in your GitLab project settings
environment:
name: production
确保您已在GitLab项目中添加了Capgo API密钥(CAPGO_TOKEN)作为CI/CD变量。前往您的项目,在GitLab中,导航到设置 > CI/CD > 变量,添加一个名为CAPGO_TOKEN的变量,并将其值设置为API密钥。
根据您的项目的具体构建过程自定义构建脚本,例如修改npm的构建命令。
结论
我们做到了!我们在技术之旅中又迈出了一个步伐。在现代软件开发中,CICD是一个不可或缺的因素。因此,我希望这份指南对每个人都有所帮助。
继续阅读Automatic build and release app with GitLab
如果您正在使用 Automatic build and release app with GitLab 来规划CI/CD自动化,连接它 Capgo CI/CD 为Capgo产品工作流程 Capgo 原生构建 为Capgo产品工作流程 Capgo 集成 为Capgo产品工作流程 CI/CD集成 为CI/CD集成的实现细节 GitHub 动作集成 为GitHub动作集成的实现细节