Google Cloud Storage
How to publish build artifacts to Google Cloud Storage using codemagic.yaml
In order to publish your generated artifacts to Google Cloud Storage:
Log in to your Google Cloud platform console.
Create a new service account under IAM & Admin > Service Accounts.Find more information about how to create a service account here.
Generate a JSON key for the service account and download it.
Open your Codemagic app settings, and go to the Environment variables tab.
Enter
GCLOUD_STORAGE_KEY
as the Variable name.Copy and paste the content of the JSON key file as Variable value.
Enter the variable group name, e.g. google_credentials. Click the button to create the group.
Make sure the Secure option is selected.
Click the Add button to add the variable.
Go to your Google Cloud Platform console and open Cloud Storage. Make a note of the name of the bucket you want to upload to or create a new bucket.
In case of an existing bucket, make sure that necessary permissions are configured.
To set up permissions go to the permission section of the bucket, Click on + Add and add the service account details with the role of Storage Object Creator and click save.
- Configure your
codemagic.yaml
by adding the following script in your post-publishing step.Replacegs://YOUR_BUCKET_NAME
with your own bucket name.
publishing:
scripts:
- name: Publish to Google Cloud
script: |
echo $GCLOUD_STORAGE_KEY > $CM_BUILD_DIR/gcloud_storage_key.json
gcloud auth activate-service-account --key-file $CM_BUILD_DIR/gcloud_storage_key.json
gsutil cp $CM_BUILD_DIR/app/build/outputs/**/*.apk gs://YOUR_BUCKET_NAME
After completing steps above, you can go to your Cloud Storage account and check if the object is uploaded.