'How can we change two values dynamically by using one variable? in yaml script?
we are using gitlab for ci/cd we have two branches for frontend dev branch-
workflow:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "uat"
when: always
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH != "dev" || $CI_COMMIT_BRANCH != "uat"
when: never
default:
image: node:xx.xx.x
stages:
- build
- deploy
build:
stage: build
script:
- npm i
- npm run build:dev
only:
- dev
- merge_requests
artifacts:
paths:
- build
deploy:
stage: deploy
image:
name: amazon/aws-cli
entrypoint: [""]
script:
- aws --version
- aws s3 rm s3://XXXXXXXXXXX-dev-operation-portal --recursive
- aws s3 cp build s3://XXXXXXXXXXXX-dev-operation-portal --acl public-read --recursive
- aws cloudfront create-invalidation --distribution-id=**XXXXXXXXXXXX** --paths "/*"
only:
- dev
- merge_requests
Uat branch
workflow: rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "uat" when: always - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH != "dev" || $CI_COMMIT_BRANCH != "uat" when: never default: image: node:xx.x.x stages: - build - deploy build: stage: build script: - npm i - npm run build:uat only: - dev - merge_requests artifacts: paths: - build deploy: stage: deploy image: name: amazon/aws-cli entrypoint: [""] script: - aws --version - aws s3 rm s3://XXXXXXXXXXX-uat-operation-portal --recursive - aws s3 cp build s3://XXXXXXXXXXXX-uat-operation-portal --acl public-read --recursive - aws cloudfront create-invalidation --distribution-id=**XXXXXXXXXXXX** --paths "/*" only: - uat - merge_requests
Like here I'm using dev branch.While merging dev to uat- conflicts done, fully interchanged ,the dev content changed to the uat. But in future case,it is difficult for deployment, again in uat, we are changing the script to dev. So ,now I want common variable name, what are the names comes under dev or uat , they have a common variable like for eg: $branch .and also there is distribution id , there also I need a common variable like for eg: $distribution_id .Now I want we are having one variable($branch) with two values(dev or uat) How to change the value, if it runs in uat, uat should trigger to the value. If it runs in dev, dev should trigger to the value as same as distribution id. How can we interchange these variables according to the branch .(dynamic variable)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|