[英]How can I use different script in .gitlab-ci.yml depending on pushed branched
I have following setting in gitlab-ci.yml
file for build我在gitlab-ci.yml
文件中有以下设置用于构建
build_app:
image: node:10
stage: build
artifacts:
expire_in: 5 minute
paths:
- ./dist
script:
# - mkdir app
# - cp package*.json ./app
- npm ci
# - COPY . . ???
- npm run build --prod
As you can see my build is always with --prod
flag and when I test on test server it also starts with prod
data如您所见,我的构建始终带有--prod
标志,当我在测试服务器上进行测试时,它也以prod
数据开头
How can I make script to use ng build --prod
when I push to master
branch and ng build --configuration=stage
when I push to dev
branch ?当我推送到master
分支时,如何制作脚本以使用ng build --prod
和推送到dev
分支时的ng build --configuration=stage
?
There is only one yaml file per repository.每个存储库只有一个 yaml 文件。 But you could define what part of the script is run on what branch by using the key word only (for more details, go to documentation).但是您可以仅使用关键字来定义脚本的哪个部分在哪个分支上运行(有关更多详细信息,请参阅文档)。 This should look like this:这应该是这样的:
deploy_master:部署主:
stages: -build阶段:-构建
build: stage: build script: -"HERE YOUR COMMAND" only: - master构建:阶段:构建脚本:-“这里是您的命令”仅:-主
deploy_dev:部署开发:
stages: -build阶段:-构建
build: stage: build script: -"HERE YOUR COMMAND" only: - dev构建:阶段:构建脚本:-“这里是您的命令”仅:-开发
Just write a shell script to check the current branch that caused the ci/cd to run:只需编写一个 shell 脚本来检查导致 ci/cd 运行的当前分支:
- case "$CI_COMMIT_BRANCH" in
"master") ng build --prod; ;;
"dev") ng build --configuration=stage; ;;
esac
or maybe more readable with a simple if else:或者使用简单的 if else 可能更具可读性:
- if [ "$CI_COMMIT_BRANCH" = "master" ]; then
ng build --prod;
elif [ "$CI_COMMIT_BRANCH" = "dev" ]; then
ng build --configuration=stage;
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.