Add cloud build badges in 2 minutes.
- Create a cloud storage bucket (tutorial here).
- Create a folder in the bucket named
build
. - Download failure and success badges (follow links and save).
- Upload both badges to the google storage bucket/folder created in the previous step (e.g.
YOUR_BUCKET/build/success.svg
). - Create a placeholder for your badge (e.g.
YOUR_BUCKET/build/BADGE_ID.svg
(make permissions public). - Set ENV Variables.
export REPO="YOUR_REPO" // e.g. github_sbsends_cloud_build_badge
export BRANCH="YOUR_BRANCH" // e.g. master
export BUCKET="YOUR_BUCKET" // e.g. my-gcp-bucket
export BADGE="PATH_TO_PUBLIC_BADGE" // e.g. cbb-master-badge
- Clone this repository into any directory.
git clone https://github.com/sbsends/cloud-build-badge.git
cd cloud-build-badge
- Use regular expressions to alter the index.js file (the cloud function).
sed -i.tmp -e "s/\${repo}/$REPO/" -e "s/\${branch}/$BRANCH/" -e "s/\${bucket}/$BUCKET/" -e "s/\${badge}/$BADGE/" index.js && rm index.js.tmp
- Deploy the cloud function as the badge name and set the function trigger to the cloud-builds pubsub topic.
gcloud functions deploy $BADGE --runtime nodejs6 --trigger-resource cloud-builds --trigger-event google.pubsub.topic.publish
- Add badge to README.md
# README.md
[![cloud build status](https://storage.googleapis.com/<BUCKET>/build/<BADGE>.svg)](https://github.com/sbsends/cloud-build-badge)