Search code examples
google-cloud-platformcontinuous-integrationyoctogoogle-cloud-build

How to start a GCP VM in a pipeline?


I am kinda having this weird not meant to use for case with GCP. So there is a few things I need to do with Google Cloud Platform. We use an much stronger than at the office Ubuntu VM to build a yocto build. I can somehow not figure out what the proper .yaml is to turn on a VM in google cloud. The pipeline should run from bitbucket and is supposed to the following things

(pseudo code)

start up the vm in gcp && ssh builder@server 
cd  ./repo/build
start build && push build image to repo server
push logs to pipeline
shutdown

I am aware of google cloud build but we have some dependencies that would likely make this more or less inefficient, now I have a general idea how my yaml is suppose to look like but I could use some better pointers in this. As in I am sure this is wrong.

steps:
  - name: 'gcloud compute instances start build-server-turnoff-when-unused' 

  - name: buildstep
    script: /bin/bash build.sh

  - name: 'send logs'
    script: /bin/bash sendlogs.sh
    

  - name: gcloud compute instances stop build-server-turnoff-when-unused'

I was wondering if someone has done something like this before and could help me out?


Solution

  • I had a bit of a wrong understanding how pipelines in bitbucket exactly work, I figured out I could just download the google-cloud sdk and give commands through the pipeline.

    image: google/cloud-sdk:latest 
    
    pipelines:
      default:
        - step:
            name: "Start build instance"
            script:
              - echo ${GCLOUD_JSON_KEY} > client-secret.json
              - gcloud auth activate-service-account --key-file client-secret.json
              - gcloud config set project $project-name
              - 'gcloud compute instances start build-serve --zone=america-west4-b'