I have 3 branches dev, qa and prod and 3 corresponding environments development, testing and production. So when code is merged into specific branch I want to build only that branch and deploy to corresponding environment
dev -> development
qa -> testing
prod -> production
dev branch is the default branch for the repository.
Using only attribute, I was able to deploy to specific environment based on which branch the code is merged.
But in the build stage I am not able to figure out, how to tell gitlab to pull specific branch where the code is checked in.
When cicd pipeline pulls the code on the runner, is it always going to pull the code from the default branch or is it going to pull the code from the branch where the code checked in?
Here is my current YAML
default:
image: node:14
tags:
- my-runner
stages:
- build
- deploy
build-job:
stage: build
script:
- npm install
- npm run build:prod
- echo "Compile complete."
artifacts:
paths:
- deploy/build.zip
deploy-dev:
image: docker.xxxx/awscli
stage: deploy
environment:
name: development
script:
- aws s3 cp deploy/build.zip s3://dev-bucket
- aws lambda update-function-code --function-name dev-lambda --s3-bucket dev-bucket --s3-key build.zip --region us-west-2
only:
- dev
deploy-testing:
image: docker.xxxx/awscli
stage: deploy
environment:
name: testing
script:
- aws s3 cp deploy/build.zip s3://qa-bucket
- aws lambda update-function-code --function-name qa-lambda --s3-bucket qa-bucket --s3-key build.zip --region us-west-2
only:
- qa
deploy-production:
image: docker.xxxx/awscli
stage: deploy
environment:
name: production
script:
- aws s3 cp deploy/build.zip s3://production-bucket
- aws lambda update-function-code --function-name production-lambda --s3-bucket production-bucket --s3-key build.zip --region us-west-2
only:
- prod
