GitLab CI Pipeline:管道无法运行

问题描述 投票:0回答:3

我不知道为什么我的 Repo 的 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.

CI 功能已启用。

这是我的

.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 [email protected] "mkdir -p /home/thomas/example.com"
    # upload project files
    - scp -prq . [email protected]:/home/thomas/example.com
    # restart the container
    - ssh [email protected] "cd /home/thomas/example.com && docker-compose down && docker-compose up -d"

谢谢! 😁

gitlab gitlab-ci gitlab-ci.yml
3个回答
13
投票

正如 D Malan 在评论中指出的那样,我已将

only
的运行限制在
main
分支。但分支名称其实是
master
🤦

所以我只是将规则形式

main
更改为
master
,现在它正在运行👌


1
投票

我花了一个小时试图找出问题所在,看似我做的一切都是正确的,但这里:

  only:
    refs:
      - develop
    variables:
      - ...

我在

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


0
投票

GitLab 会不时更改其 CI 模板。

如果您的

.gitlab-ci.yml
是基于旧版本的 GitLab 模板创建的,请在 here 搜索最新版本的模板,单击 History 并查看最近是否已更改。如果有,请根据这些模板更改修改您的
.gitlab-ci.yml

例如,我刚刚发现他们变了

image: image-name

default:
   image: image-name
© www.soinside.com 2019 - 2024. All rights reserved.