Answers: <p>In  GitLab CI version 13.0 and later, the script keyword should be nested within a before_script or after_script section e.g. for the code above the middle must be replaced with</p>
  <pre><code>  before_script:
      - pip install black
    script:
      - black --check .
    allow_failure: false 
  
  testcov:
    stage: test
    image: python:3.8
    before_script:
      - pip install pytest pytest-cov
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-04-12T18:21:29.597Z
Answers: 2024-04-12T18:21:29.597Z
Answers: MosQuan
Body: <p>.gitlab-ci.yml with</p>
  <pre><code>stages:
    - test
  
  jobs:
    lint:
      stage: test
      image: python:3.8  # Assuming same image for both jobs
      script:
        - pip install black
        - black --check .  
      allow_failure: false 
  
    testcov:
      stage: test
      image: python:3.8
      script:
        - pip install pytest pytest-cov
        - pytest --cov api/
        - curl -Os https://cli.codecov.io/latest/linux/codecov
        - chmod +x codecov
        - ./codecov upload-process -t $CODECOV_TOKEN
  </code></pre>
  <p>fails with</p>
  <pre><code>This GitLab CI configuration is invalid: jobs jobs config should implement a script: or a trigger: keyword
  </code></pre>
  <p>However the same without jobs and stages is valid and works</p>
  <pre><code>lint:
    image: python:3.8  # Assuming same image for both jobs
    script:
      - pip install black
      - black --check .  
    allow_failure: false 
  
  testcov:
    image: python:3.8
    script:
      - pip install pytest pytest-cov
      - pytest --cov api/
      - curl -Os https://cli.codecov.io/latest/linux/codecov
      - chmod +x codecov
      - ./codecov upload-process -t $CODECOV_TOKEN
  </code></pre>
  <p>is there something that missing in stages version of code?</p>
  
Tags: <continuous-integration><gitlab><yaml>
Title: Stage and jobs blocks breaks gitlab CI with "configuration is invalid: jobs jobs config should implement a script: or a trigger: keyword"
UserDisplayName: MosQuan
ThreadText: # Stage and jobs blocks breaks gitlab CI with "configuration is invalid: jobs jobs config should implement a script: or a trigger: keyword"
  
  (Asked by: username_0 on 2024-04-11)
  
  .gitlab-ci.yml with
  
  ```
  stages:
    - test
  
  jobs:
    lint:
      stage: test
      image: python:3.8  # Assuming same image for both jobs
      script:
        - pip install black
        - black --check .  
      allow_failure: false 
  
    testcov:
      stage: test
      image: python:3.8
      script:
        - pip install pytest pytest-cov
        - pytest --cov api/
        - curl -Os https://cli.codecov.io/latest/linux/codecov
        - chmod +x codecov
        - ./codecov upload-process -t $CODECOV_TOKEN
  
  ```
  
  fails with
  
  ```
  This GitLab CI configuration is invalid: jobs jobs config should implement a script: or a trigger: keyword
  
  ```
  
  However the same without jobs and stages is valid and works
  
  ```
  lint:
    image: python:3.8  # Assuming same image for both jobs
    script:
      - pip install black
      - black --check .  
    allow_failure: false 
  
  testcov:
    image: python:3.8
    script:
      - pip install pytest pytest-cov
      - pytest --cov api/
      - curl -Os https://cli.codecov.io/latest/linux/codecov
      - chmod +x codecov
      - ./codecov upload-process -t $CODECOV_TOKEN
  
  ```
  
  is there something that missing in stages version of code?
  
  **Tags:** continuous-integration, gitlab, yaml
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-04-12. Score: 0
  
  In GitLab CI version 13.0 and later, the script keyword should be nested within a before\_script or after\_script section e.g. for the code above the middle must be replaced with
  
  ```
    before_script:
      - pip install black
    script:
      - black --check .
    allow_failure: false 
  
  testcov:
    stage: test
    image: python:3.8
    before_script:
      - pip install pytest pytest-cov
  
  ```
  
  
  ---
  
  