跳过主要内容
CI/CD

使用GitLab自动构建和发布应用

Create your own CI/CD pipeline with GitLab for free, deploy your Ionic Capacitor JS app every time you push to main.

文章来源

马丁·多纳迪厄

作者

瓦莱里亚

审阅者

乔丹

编辑

使用GitLab自动构建和发布应用

本文将指导您如何在 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动作集成的实现细节

实时更新的Capacitor应用

当一个web层bug在live状态时,通过Capgo将修复推送到用户,而不是等待几天的app store审批。用户在后台接收更新,而native层的改变仍然在正常的审批路径中。

来自Martin的专业支持

立即开始

最新博客

Capgo为您提供了创建真正专业的移动应用所需的最佳见解。