我目前正在为我的react项目设置gitlab-ci.yml文件。我不知道为什么,但如果项目编译失败,gitlab的工作仍然成功。我们可以在gitlab的工作详细信息中看到:
Creating an optimized production build...
Failed to compile.
./src/pages/page500/Page500.js
Line 26:81: Unexpected use of 'history' no-restricted-globals
Search for the keywords to learn more about each error.
Running after_script
00:01
Saving cache
00:01
Uploading artifacts for successful job
00:02
Job succeeded请在下面找到gitlab-ci.yml文件:
stages:
- build_test
- build_production
- deploy_test
- deploy_production
build_test:
image: node:12.17.0
stage: build_test
tags:
- npm-build
script:
- unset CI
- npm install
- npm run build:development
only:
- development
artifacts:
when: on_success
name: settlement-build-development
paths:
- build
expire_in: 1 hour
build_production:
image: node:12.17.0
stage: build_production
tags:
- npm-build
script:
- unset CI
- npm install
- npm run build:production
only:
- master
artifacts:
when: on_success
name: settlement-build-production
paths:
- build
expire_in: 1 hour
deploy_test:
image: alpine
stage: deploy_test
tags:
- deploy
script:
- apk add --no-cache rsync openssh
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
- chmod 600 ~/.ssh/id_dsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- rsync -rav --delete ./build/ -e 'ssh -p 2222' user@XX.XXX.XX.XX:/var/www/website.com/
only:
- development
deploy_production:
image: alpine
stage: deploy_production
tags:
- deploy
script:
- apk add --no-cache rsync openssh
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
- chmod 600 ~/.ssh/id_dsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- ls -lah ./build/
- rsync -rav --delete ./build/ -e 'ssh -p 2222' user@XX.XXX.XX.XX:/var/www/website.com/
only:
- master请找到packages.json的脚本部分:
"scripts": {
"start": "react-scripts start",
"build": "react-app-env --env-file=.env.${BUILD_ENV} build",
"build:development": "BUILD_ENV=development npm run build",
"build:production": "BUILD_ENV=production npm run build",
"test": "react-scripts test",
"test:cov": "npm test -- --coverage --watchAll=false",
"test:debug": "react-scripts --inspect-brk test --runInBand",
"eject": "react-scripts eject"
},有人已经在gitlab上遇到这个问题了吗?
提前使用THanks
发布于 2021-11-24 16:45:03
要解决您的问题,您需要明确地使您的构建失败!
要做到这一点,如果构建失败,您只需添加|| exit 1:
"build:production": "BUILD_ENV=production npm run build || exit 1",这将使CI停止并执行exit 1;
https://stackoverflow.com/questions/63329497
复制相似问题