4
1

More than 1 year has passed since last update.

BitriseのmacOSスタックにGoogle Cloud SDKをインストールして使う

Posted at

普段Bitriseを使ってiOSアプリのCIをしていて、ビルド成果物をGoogle Cloud Storageにアップロードしたりしています。

Google Cloud Storageとやり取りするにはgcloudgsutilといったコマンド群を含むGoogle Cloud SDKが必要なのですが、残念ながらmacOSスタックにはインストールされていません。

Xcode14.2 macOS Venturaのスタック情報はこちら。
https://github.com/bitrise-io/bitrise.io/blob/master/system_reports/MACOS/M1/osx-xcode-14.2.x-ventura.log

本記事では、macOSスタックにGoogle Cloud SDKをインストール&キャッシュして、次回以降のビルドですぐにコマンドを使えるようにする方法をご紹介します。

Google Cloud SDKのインストール&キャッシュ

ワークフローにScriptステップを追加し、以下のスクリプトを入れておきます。

#!/usr/bin/env bash
# fail if any commands fails
set -e
# make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully
set -o pipefail
# debug log
set -x

# write your script here
if [ ! -d $HOME/google-cloud-sdk ]; then
  curl https://sdk.cloud.google.com | bash 
fi
source $HOME/google-cloud-sdk/path.bash.inc
gcloud components update

image.png

次に、ワークフローにCache:Pushステップを追加し、以下のパスを入力します。

$HOME/google-cloud-sdk

image.png

これらのステップの追加により、以下の処理が行われます。

  • $HOME/google-cloud-sdkディレクトリがなければSDKをインストールする
  • SDKを最新にアップデートする
  • $HOME/google-cloud-sdkディレクトリをキャッシュする

私は上記ステップを加えたワークフローを毎晩ビルドするようにして、常に最新のSDKがキャッシュされた状態にしています。

こうすることで、他のワークフローではSDKをインストールする必要がなく、すぐにgsutil等のコマンドを使用することができます。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1