GCP Cloud Run - How to trigger deployment from Bitbucket Pipelines

We have a .NET 5 web application that is built in Bitbucket Pipelines and then has the Docker image pushed into the GCP Registry

Within Octopus Cloud I have setup a deployment using the gcloud CLI to deploy an image to Cloud Run e.g.

gcloud run deploy $ProjectName --image=$ImageName --platform managed --region europe-west2 --allow-unauthenticated --set-env-vars=NODE_ENV=‘production’

Currently I have to hard code the Docker image name and manually trigger the deployment in Octopus

My questions are

  • How can I have Bitbucket Pipelines trigger the deployment in Octopus Cloud? Is this simply a case of calling the Octopus API from Bitbucket Pipeliens?
  • How can I pass in the Docker image name from Bitbucket Pipelines to be used by Octopus Cloud? My thinking is that this should be passed in externally and then used by Octopus to ensure the same image is deployed to all environments as it’s promoted

Thanks

Greetings @PeterBridgerKaptio, thanks for reaching out! For the first question, we have an example BitBucket pipeline that you can refer to Bitbucket, I’ve included the specific YAML here for brevity.

      - step:
          name: octo deploy-release
          script:
            - pipe: octopusdeploy/octopus-cli-run:0.23.0
              variables:
                CLI_COMMAND: 'deploy-release'
                OCTOPUS_SERVER: $OCTOPUS_SERVER
                OCTOPUS_APIKEY: $OCTOPUS_API_KEY
                OCTOPUS_SPACE: $OCTOPUS_SPACE
                PROJECT: $OCTOPUS_PROJECT
                RELEASE_NUMBER: 'latest'
                DEPLOY_TO: ['Development']
                DEBUG: 'false'

For the second question, it looks like the $ImageName is an Octopus Project variable?

Thanks for the prompt response @Shawn_Sesna

Your suggestion for question one looks promising, I’ll investigate this

For the second question, $ImageName is a Bash variable being set. To add more context, this is the entire Bash script being run

ImageName=“Google Cloud console
ProjectName=“$(get_octopusvariable “GCP.CloudRun.ProjectName”)”
Region=“$(get_octopusvariable “GCP.Region”)”

echo “Deploying $ProjectName in region $Region with image $ImageName”

Deploy image to Cloud Run

gcloud run deploy $ProjectName --image=$ImageName --platform managed --region $Region --allow-unauthenticated --set-env-vars=NODE_ENV=‘production’

There’s a couple of different ways I think we might be able to achieve this. Script tasks have the ability to reference packages, do you think you can use a package reference pulling from a docker container registry and get the image that way?

If not, the second option would be a prompted variable, however, it does come with challenges. The prompted variable would need to be provided each time it ran, so when it goes from environment to environment, it would need to be provided again. There is some API wizardry we could do for this, but it would make the process much more complex.

I’m using GitVersion to generate a SemVer based version in Bitbucket Pipelines and using this to tag the container image.

As this version number is also being used in the create release call to Octopus, I’m then able to reserve engineer the container image name based upon this within Octopus from the Octopus.Release.Number variable as you suggest.

Thanks for your help

Nice!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.