Skip to main content

Using Ionic Cloud CLI with Azure DevOps

note

This feature is only available on our Standard or Enterprise plans. Please contact us to enable this feature.

Introduction#

You can utilize Live Updates, Native Builds, and App Store Publishing from the Ionic Cloud CLI inside of an Azure DevOps Pipeline.

This example will walk you through setting up a pipeline in Azure DevOps that takes you repo, performs an iOS Build for TestFlight, saves it to Azure DevOps as an artifact, and then pushes it directly to TestFlight.

Requirements#

For this example, we've already done the following in our Appflow dashboard:

  1. Set up a Personal Access Token
  2. Connected our Azure DevOps Repo to an Appflow App
  3. Created a Signing Credential for iOS App Store (Production), and added to Appflow as "TestFlight"
  4. Added an App Store Destination as "TestFlight"

Creating a Pipeline#

Navigate to the Pipelines section of your Azure DevOps dashboard and click "New Pipeline." For this example we're choosing "Azure Repos Git" as our repository, and "Starter pipeline" as the default configuration.

Azure DevOps Pipeline Dashboard

Writing our Pipeline#

Once we've created our pipeline, we'll be dropped into the Pipeline editor, which looks like this:

Azure DevOps Pipeline Editor

The first thing we'll want to do is add our Personal Access Token as a Variable. Click on "Variables" in the top right, and set up a new Variable with the name IONIC_TOKEN and the value of your PAT. Mark this variable as a Secret, then click OK.

Now that we have access to our IONIC_TOKEN we can write a pipeline. The steps for this example are going to be:

  1. Install Ionic Cloud CLI
  2. Run an iOS build in Appflow
  3. Publish our IPA file as an artifact in Azure DevOps
  4. Deploy to TestFlight in Appflow

Be sure to replace AppIdEx123abc with your actual App ID from the Appflow Dashboard. You can find this by opening your app in Appflow and looking under its name in the top left.

Full yaml Script#

# Starter pipeline# Start with a minimal pipeline that you can customize to build and deploy your code.# Add steps that build, run tests, deploy, and more:# https://aka.ms /yaml
trigger:- master
pool:  vmImage: ubuntu-latest
variables:- name: iosbuildid
steps:- script: curl -sL https://ionic.io/get-ionic-cloud-cli | bash  displayName: 'Install Ionic Cloud CLI'
- script: |    BUILDID=$(ionic-cloud build ios app-store --app-id AppIdEx123abc --commit $(Build.SourceVersion) --signing-cert "TestFlight" --ipa-name "app.ipa" --json --token $(IONIC_TOKEN) | jq -r '.buildId')    echo "##vso[task.setvariable variable=iosbuildid]$BUILDID"  displayName: 'Run an iOS build in Appflow'
- publish: $(System.DefaultWorkingDirectory)/app.ipa  artifact: iOSApp
- script: |    ionic-cloud deploy ios --app-id AppIdEx123abc --build-id $(iosbuildid) --destination "TestFlight" --token $(IONIC_TOKEN)  displayName: 'Deploy to TestFlight in Appflow'

Add a Pipeline Variable#

Let's walk through this pipeline step by step. First we added a variable:

variables:- name: iosbuildid

We'll use this variable later to store the build ID that came back from our iOS build, so that we can deploy it.

Ionic Cloud CLI Installation#

Then we installed the Ionic Cloud CLI:

steps:- script: curl -sL https://ionic.io/get-ionic-cloud-cli | bash  displayName: 'Install Ionic Cloud CLI'

Perform an iOS Build#

After that we added a multiline Step that does a few different things. The primary part of this command is ionic-cloud build ios app-store --app-id AppIdEx123abc --commit $(Build.SourceVersion) --signing-cert "TestFlight" --ipa-name "app.ipa" --json --token $(IONIC_TOKEN) which actually performed the build.

We included | jq -r '.buildId' after that to parse the Build ID from Appflow out of the responses JSON, so that we can store it.

Then we wrapped everything up in a BUILDID=$( ) to save the return value to the system. The next line echo "##vso[task.setvariable variable=iosbuildid]$BUILDID" saves BUILDID to the pipeline variable iosbuildid that we set up earlier, so that we can use it in the deployment step.

- script: |    BUILDID=$(ionic-cloud build ios app-store --app-id AppIdEx123abc --commit $(Build.SourceVersion) --signing-cert "TestFlight" --ipa-name "app.ipa" --json --token $(IONIC_TOKEN) | jq -r '.buildId')    echo "##vso[task.setvariable variable=iosbuildid]$BUILDID"  displayName: 'Run an iOS build in Appflow'

Save an Artifact#

Since our previous step included --ipa-name "app.ipa" our IPA file was automatically downloaded and renamed. Let's utilize Azure DevOps publish artifact system to save this file as an artifact.

- publish: $(System.DefaultWorkingDirectory)/app.ipa  artifact: iOSApp

Deploy to TestFlight#

Finally, we utilize the iosbuildid pipeline variable inside of our deployment command to take this build and automatically push it to App Store Connect for use in TestFlight.

- script: |    ionic-cloud deploy ios --app-id AppIdEx123abc --build-id $(iosbuildid) --destination "TestFlight" --token $(IONIC_TOKEN)  displayName: 'Deploy to TestFlight in Appflow'

Save and Run#

When you save this pipeline, it will automatically run! You should see all build output and errors ported directly back to your Azure DevOps dashboard like so:

Azure DevOps Finished Pipeline

Next Steps#

This example walked through setting up an iOS build automated throught to Testflight, but you can also create Pipelines for Android builds, or Live Updates. See the other Cloud CLI documentation or run ionic-cloud --help to learn more about what functions are available in the Ionic Cloud CLI.

Locking the Ionic Cloud CLI Version#

If you'd like to lock the version of Ionic Cloud CLI in place for your pipeline, use the following command to install the Ionic Cloud CLI instead: export IONIC_CLOUD_VERSION=X.X.X; curl -sL https://ionic.io/get-ionic-cloud-cli | bash, replacing X.X.X with your desired version number.

Contact Us#