我正在尝试使用下面的
.gitlab-ci.yml
构建管道。我的问题是,当我添加分支条件(例如下面的 if
或 onyl: -dev
)时,我的构建阶段在整个管道过程中消失。请参阅管道页面图片
我的 GitLab 运行器是一个在 Linux 主机上运行的 shell 执行器。
注意:如果我不添加分支条件,一切都会按预期工作,并且管道会成功完成。
我是 Gitlab CI/CD 新手。有人对这个问题有想法吗?谢谢。
image: node:18
stages:
- lint
- build
- deploy
lint_app:
stage: lint
before_script:
- export PATH=/home/DEVICE_NAME/.nvm/versions/node/v20.11.0/bin:$PATH
- npm install
script:
- npm run prettier
- npm run lint
rules:
- if: '$CI_COMMIT_BRANCH == "dev"'
build_app:
stage: build
before_script:
- export PATH=/home/DEVICE_NAME/.nvm/versions/node/v20.11.0/bin:$PATH
script:
- npm run build
artifacts:
paths:
- dist/
rules:
- if: '$CI_COMMIT_BRANCH == "dev"'
deploy_app:
stage: deploy
before_script:
- export PATH=/home/DEVICE_NAME/.nvm/versions/node/v20.11.0/bin:$PATH
script:
- npm run start
rules:
- if: '$CI_COMMIT_BRANCH == "dev"'
将
when: always
添加到您的 gitlab-ci 文件中:
rules:
- if: $CI_COMMIT_BRANCH == "dev"
when: always