GitLab CI流水线:无法运行流水线

4

我找不出为什么我的代码库的GitLab CI Pipelines无法运行。我有一个.gitlab-ci.yml文件,并启用了该功能,但管道无法运行。此外,如果我尝试手动触发管道,会返回以下错误。

Pipeline cannot be run.
Pipeline will not run for the selected trigger. The rules configuration prevented any jobs from being added to the pipeline.

enter image description here

启用了CI功能。

enter image description here

这是我的.gitlab-ci.yml文件。
stages:
  - build
  - deploy

npm-run-build:
  stage: build
  image: node:19
  only: 
    - main
  cache:
    key: ${CI_COMMIT_REF_SLUG}-build
    paths:
      - dist/
  script:
    - cp .env.example .env
    - npm ci
    - npm run build-only
deploy-dist:
  stage: deploy
  image: fedora:latest
  only: 
    - main
  environment:
    name: production
    url: https://example.com
  needs:
    - npm-run-build
  cache:
    key: ${CI_COMMIT_REF_SLUG}-build
    paths:
      - dist/
      
  before_script:
    - dnf install -y openssh-clients
    - mkdir -p ~/.ssh
    - echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
    - chmod 600 ~/.ssh/id_rsa
    - ssh-keyscan -t rsa example.com > ~/.ssh/known_hosts
  script:
    # create remote project dir if not available
    - ssh thomas@example.com "mkdir -p /home/thomas/example.com"
    # upload project files
    - scp -prq . thomas@example.com:/home/thomas/example.com
    # restart the container
    - ssh thomas@example.com "cd /home/thomas/example.com && docker-compose down && docker-compose up -d"

谢谢!😁


3
你正在尝试在哪个分支上运行你的流水线? - D Malan
哦,我的天啊,我又瞎了! 谢谢! - Thomas Venturini
2个回答

10

正如D Malan在评论中指出的那样,我已经将only的运行限制仅限于main分支。但实际上分支名称应该是master

所以我只需将规则从main更改为master,现在它正在运行


1
我花了一个小时试图弄清楚问题出在哪里,看起来我做的一切都是正确的,但是在这里:
  only:
    refs:
      - develop
    variables:
      - ...

我在variables部分中有一个不存在的变量。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接