Skip to main content

Parsing --json Output from Ionic Cloud CLI

Introduction#

When including --json as a flag for a build or deploy, several helpful pieces of information will be returned once the command finishes running in a parsable JSON format.

This is extremely useful when performing separate build and deploy commands where you'd like to deploy the thing you just built.

Saving a Variable#

First, let's perform a Build utilizing the Ionic Cloud CLI like so (be sure to replace your own --app-id, --commit, and --token):

ionic-cloud build android debug --app-id AppIdEx123abc --commit abc123 --token $(IONIC_TOKEN) --json

Running this command (or any other command) with --json will show you the specific JSON that is returned from that command.

In this case we're performing a build, so let's grab the buildId and save it to a variable using jq (preinstalled on most CI/CD platforms).

BUILDID=$(ionic-cloud build android debug --app-id AppIdEx123abc --commit abc123 --token $(IONIC_TOKEN) --json  | jq -r '.buildId')

Using a Variable Later#

The BUILDID bash variable should now be available to use in the next command. An example of that would be the following (where you've already set up a Destination called "GooglePlay"):

ionic-cloud deploy android --app-id AppIdEx123abc --build-id $(BUILDID) --destination "GooglePlay" --token $(IONIC_TOKEN)