GitLab CI Pipeline: Pipeline cannot be run
Asked Answered
C

3

11

I can't find out why the GitLab CI Pipelines for my Repo won't run. I have a .gitlab-ci.yml file and the feature enabled, but the pipeline won't run. Also if I try to trigger the pipeline manually I get the following error back.

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

The CI feature is enabled.

enter image description here

Here is my .gitlab-ci.yml file.

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"

Thank you! 😁

Coastline answered 30/1, 2023 at 14:47 Comment(2)
On which branch are you trying to run your pipeline? – Parget
oh my god, I'm blind again! πŸ™ˆ Thank you! – Coastline
C
18

As D Malan pointed out in the comments, I have restricted the runs with only to the main branch. But the branch name is actually master 🀦

So I just changed the rule form main to master and now it is running πŸ‘Œ

Coastline answered 1/2, 2023 at 5:40 Comment(1)
Please mark the answer as correct so it will have the GREEN V – Medicable
K
1

I've spent an hour trying to figure out what's wrong, seemingly I did everything right, but here:

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

I had a non existent variable in the variables section.

Katharynkathe answered 4/8, 2023 at 6:20 Comment(0)
Y
0

GitLab changes its CI templates from time to time.

If your .gitlab-ci.yml was created based on an older version of a GitLab template, search for the latest version of the template here, click History and see if it's changed recently. If it has, modify your .gitlab-ci.yml according to these template changes.

For example, I have just found out that they had changed

image: image-name

to

default:
   image: image-name
Yachting answered 27/3 at 17:28 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.