You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Visual Studio Online实现Cordova/PhoneGap构建与持续集成交付?

Setting Up Cordova/PhoneGap Builds & CI/CD in Visual Studio Online (VSO)

Great question! Even though VSO doesn’t include a dedicated Cordova/PhoneGap build template, you can easily set up custom builds and full CI/CD pipelines with a few manual steps. Let’s break this down step by step.

Part 1: Creating a Cordova Build Process in VSO

1. Prepare Your Build Agent

First, make sure your VSO build agent has all the required tools installed:

  • Node.js: Cordova relies on Node, so install a stable LTS version.
  • Cordova CLI: You can install it globally on the agent with npm install -g cordova, or add it as a project dependency (we’ll cover that option later).
  • Platform-specific SDKs: For Android, install the Android SDK and set the ANDROID_HOME environment variable. For iOS, you’ll need a macOS agent with Xcode and proper developer certificates/provisioning profiles configured.

2. Create a Custom Build Definition

Start with an empty process since there’s no pre-built template:

  1. Go to your VSO project’s Builds tab and click New build definition.
  2. Select Empty process and click Apply.

3. Add Build Steps

Now add these steps to your build pipeline (in order):

  • Get Sources: This is added by default—just confirm it’s pointing to your Cordova project repository.
  • Install Node Dependencies: Add an npm task, set the command to install, and point it to your project’s package.json file. This installs all project dependencies, including any local Cordova version if you’ve added it to package.json.
  • Install Cordova CLI (if not global): If you didn’t install Cordova globally on the agent, add another npm task with the command install -g cordova. Alternatively, use npx cordova in subsequent commands to avoid global installs.
  • Add Target Platform: Add a Command Line task with the script:
    cordova platform add android --save
    
    Swap android for ios if building for iOS.
  • Build the Cordova Project: Add another Command Line task with the release build command:
    cordova build --release android
    
    Adjust the platform and add flags like --debug if you need a debug build.
  • Publish Build Artifacts: Add a Publish Build Artifacts task to save your generated .apk (Android) or .ipa (iOS) file. Set the artifact name to something like CordovaApp and the path to the build output (e.g., platforms/android/app/build/outputs/apk/release/ for Android).

Part 2: Setting Up Continuous Integration & Delivery (CI/CD)

1. Enable Continuous Integration (CI)

Trigger builds automatically when code is pushed:

  1. In your build definition, go to the Triggers tab.
  2. Toggle on Continuous integration.
  3. Select the branches you want to trigger builds for (e.g., main, develop).
  4. Save the build definition—now every code push to those branches will kick off a build.

2. Set Up Continuous Delivery (CD)

Deploy your built app automatically to testing or production environments:

  1. Go to your VSO project’s Releases tab and click New release definition.
  2. Select Empty process and click Apply.
  3. Link Build Artifacts: Add an artifact source pointing to your Cordova build definition.
  4. Add Deployment Steps:
    • For Android: Use the Google Play task to deploy your .apk to the Play Store (either internal testing, beta, or production). You’ll need to configure your Google Play service account credentials.
    • For iOS: Use the App Store Connect task to upload your .ipa to Apple’s App Store. Make sure your macOS agent has the correct certificates and provisioning profiles.
    • For testing environments: You can add tasks to distribute the app to testing tools like Firebase App Distribution or TestFlight.
  5. Configure Deployment Triggers: Go to the Triggers tab of your release definition, toggle on Continuous deployment, and select the build branch you want to deploy automatically.
  6. Add Environments (Optional): Set up multiple environments (e.g., Test, Staging, Production) with approval gates if you want to manually sign off before deploying to production.

Key Tips & Troubleshooting

  • Use variables to make your pipeline flexible: Define variables like $(platform) or $(buildConfiguration) so you can easily switch between Android/iOS or debug/release builds without editing tasks.
  • For iOS builds: Ensure your macOS agent has the correct developer certificates installed, and use cordova build ios --release --developmentTeam="YOUR_TEAM_ID" to specify your team ID.
  • Logs: If builds fail, check the build logs—VSO will show you exactly where a step broke (e.g., missing dependencies, SDK errors).

内容的提问来源于stack exchange,提问作者Doug Thompson - DouggyFresh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:44:17