Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab-ci.yaml `config contains unknown keys: rules` when trying to use rules

Tags:

gitlab-ci

I've pasted the example for rules in my gitlab-ci.yaml (from https://docs.gitlab.com/ee/ci/yaml/#rules):

job:
  script: "echo Hello, Rules!"
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH == "master"'
      when: always
    - if: '$VAR =~ /pattern/'
      when: manual
    - when: on_success

But I get

Error: jobs:job config contains unknown keys: rules

Am I missing something?

like image 585
Gavin Haynes Avatar asked Aug 27 '19 23:08

Gavin Haynes


People also ask

What is Before_script in GitLab CI?

These are scripts that you choose to be run before the job is executed or after the job is executed. These can also be defined at the top level of the YAML file (where jobs are defined) and they'll apply to all jobs in the . gitlab-ci. yml file.

What is a GitLab CI Yml file?

GitLab CI uses a YAML file ( . gitlab-ci. yml ) for project configuration. This file is placed in the root of the repository and defines the project's Pipelines, Jobs, and Environments. The YAML file defines a set of jobs with constraints for when they should be run.

Where is GitLab CI Yml located?

From version 7.12, GitLab CI uses a YAML file ( . gitlab-ci. yml ) for the project configuration. It is placed in the root of your repository and contains definitions of how your project should be built.

What is extends in GitLab CI?

Here is the definition from GitLab documentation: extends defines entry names that a job that uses extends inherits from. It's an alternative to using YAML anchors and is a little more flexible and readable. So, when is it useful? It is useful when you want to be DRY and keep your setup cleanly.


1 Answers

This feature is currently only available on gitlab.com.

Check the version of the instance you use and select the corresponding gitlab docs (in the header bar of the gitlab docs pages) eg https://docs.gitlab.com/12.2/ee/ci/yaml/README.html.

like image 132
user12013688 Avatar answered Oct 14 '22 03:10

user12013688