首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GITLAB CI - React应用程序构建失败,但作业成功

GITLAB CI - React应用程序构建失败,但作业成功
EN

Stack Overflow用户
提问于 2020-08-10 01:44:10
回答 1查看 196关注 0票数 0

我目前正在为我的react项目设置gitlab-ci.yml文件。我不知道为什么,但如果项目编译失败,gitlab的工作仍然成功。我们可以在gitlab的工作详细信息中看到:

代码语言:javascript
复制
 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文件:

代码语言:javascript
复制
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的脚本部分:

代码语言:javascript
复制
 "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

EN

回答 1

Stack Overflow用户

发布于 2021-11-24 16:45:03

要解决您的问题,您需要明确地使您的构建失败!

要做到这一点,如果构建失败,您只需添加|| exit 1

代码语言:javascript
复制
"build:production": "BUILD_ENV=production npm run build || exit 1",

这将使CI停止并执行exit 1;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63329497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档