Parsing --json Output from Appflow 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 newly built artifact.
Saving a Variable
First, let's perform a Build utilizing the Appflow CLI like so (be sure to replace your own --app-id, --commit, and --token):
appflow 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=$(appflow 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"):
appflow deploy android --app-id AppIdEx123abc --build-id $(BUILDID) --destination "GooglePlay" --token $(IONIC_TOKEN)