Nejmeddine Ben Ouarred
2 min readDec 29, 2020


In this article, I will demonstrate the list of steps to deploy to Cloud Run from your GitLab repository.

For that, you need to have:

  • Gitlab repository
  • GCP project

In the GCP project, you MUST follow steps bellow:

  • activate API fro Cloud RUN
  • create a service account having as IAM roles: Cloud Run Admin & Run Service Agent
  • create key (json format) for the created service account

In your Gitlab repository, you MUST create:

  • .gitlab-ci.yml
  • upload the service account key file in the (CI / CD Settings -> variable).

I decided to pusblish docker image to Cloud Registry (I will move to Cloud Artifact Registry asap), then I deploy the last published image to cloud Run.

Below, the two stages that allow you to do that:

  • Fist, I build the docker image, tag it and then push it to Cloud Registry
stage: package
- echo "******** Starting docker build & gcr push ********"
- docker login -u _json_key --password-stdin < "$GCR_CREDENTIAL"
- docker build -t api .
- docker tag api$GCP_PROJECT_ID/api
- docker push$GCP_PROJECT_ID/api
  • Then, I deploy it to a cloud RUN (already created using GCP Consol)
when: manual
stage: deploy
image: google/cloud-sdk
- docker:dind
- gcloud config set project $GCP_PROJECT_ID
- gcloud auth activate-service-account --key-file "$CLOUD_RUN_DEPLOYER"
- gcloud run deploy CLOUD_RUN__SERVICE_NAME --image$GCP_PROJECT_ID/api:latest --platform=managed --region=europe-west1 --project=$GCP_PROJECT_ID

Let’s build :) !



Nejmeddine Ben Ouarred

Certified GCP Architect | GCP Authorized trainer | Certified Google APIGEE | APIGEE Authorized trainer