Davtho1983
Davtho1983

Reputation: 3954

Deploy to different firebase sites depending on which branch I push to

It would be great to have CI/CD with firebase hosting and a develop site for testing and a production site which is the live production version.

I want to have a firebase trigger that detects when I push to the develop branch on my git repo, and that should trigger a deploy to the develop site.

I want a separate trigger that detects when I merge into my master branch, and that should deploy to the production site.

My targets are set up correctly and they work.

This is my cloudbuild.yaml currently deploying to both sites:

steps:
    # Install
    - name: 'gcr.io/cloud-builders/npm'
      args: ['install']
    # Build
    - name: 'gcr.io/cloud-builders/npm'
      args: ['run', 'build']
    # Deploy-develop
    - name: 'gcr.io/host-test-xxxxx/firebase'
      args: ['deploy', '--only=hosting:develop']
    # Deploy-production
    - name: 'gcr.io/host-test-xxxxx/firebase'
      args: ['deploy', '--only=hosting:production']

How do I add a thing that detects which branch I pushed to and only executes either the Deploy-develop or Deploy-production bit, but not both?

Upvotes: 0

Views: 681

Answers (1)

Davtho1983
Davtho1983

Reputation: 3954

This can be done with trigger variables - I adapted this tut: tut

After creating target aliases called production and develop for two sites in firebase hosting I added Substitution variables to my triggers called _DEPLOY_TO

Then I changed the script in my cloudbuild.yaml to:

# Deploy
    - name: 'gcr.io/host-test-xxxxx/firebase'
      args: ['deploy', '--only=hosting:$_DEPLOY_TO']

Upvotes: 1

Related Questions