Order of keywords in jobs

Created on 11 April 2025, 7 days ago

Problem/Motivation

Following from an initial conversation on Slack here is a suggestion for code improvement within the two template files, to re-order the keys/elements within each job to an agreed order. This will allow more easy comparison between jobs and/or to see which ones do not have a certain keyword.

Proposed resolution

Many of the jobs already follow a similar sequence of keywords, and from observation a common order is:

stage
image
extends
services
rules
needs
allow_failure ?
variables
artifacts ?
before_script
script
after_script

This is only a first suggestion, we can adjust this if required.

There are lots of jobs that already follow this sequence:

  • composer-base and all composer variants
  • composer-lint
  • all phpstan variants
  • nightwatch, nightwatch max php & previous minor
  • phpunit, phpunit max, & previous minor
  • test-only changes
  • environment check
  • deprecation-warning-base

The other jobs should only need one or two keys moved to match this order.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Component

gitlab-ci

Created by

🇬🇧United Kingdom jonathan1055

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jonathan1055
  • 🇬🇧United Kingdom jonathan1055

    The above order is what we have mostly been following, but I thought it worth taking a look to see what other developers do, and/or if there is consensus

    Tim Plavec on Medium suggests an order that is fairly close to what we are already are doing:
    https://tinplavec.medium.com/gitlab-ci-cd-best-practices-i-recommend-aft...

    extends
    stage
    needs
    rules
    tags    << we do not use tags 
    image
    environment << we do not use 
    variables
    script
    allow_failure
    artifacts
    cache  << we do not use 
    

    He does not have 'services' in his list. I have not found any other recommended orderings.

    His idea of having artifacts at the end sounds quite good. They are logically produced by the script, at the end of the job.

    It would also be quite easy to write a simple script to verify the order in our two files, but Gitlab Templates own .gitllab-ci.yml, and run this as part of our code checks. We won't be adding too many new items very often, but the script would help us to get the order right, and keep it so.

  • Merge request !347#3518793 Keyword order in job templates → (Open) created by jonathan1055
  • Pipeline finished with Failed
    6 days ago
    Total: 82s
    #472004
  • 🇬🇧United Kingdom jonathan1055

    Initial commit, with a php script to check the keyword order. It failed as intended, because I have not moved any of the keywords, and also left some undefined, to demonstrate the output.

    Tangentially related, I noticed that the project's .gitlab-ci.yml is being ignored by the eslint check. We do not have a .eslintignore or .prettierignore file, and even using --no-ignore locally this file is still not tested. I adde --debug to check what happens in the pipeline, and it is ignored just like when running locally, and I don't know why.

    2025-04-12T16:55:27.106Z eslintrc:ignore-pattern Check {
      filePath: '/builds/issue/gitlab_templates-3518793/.gitlab-ci.yml',
      dot: false,
      relativePath: '.gitlab-ci.yml',
      result: true
    }
    2025-04-12T16:55:27.106Z eslint:file-enumerator Yield: .gitlab-ci.yml but ignored

    See this part of the log

  • Pipeline finished with Failed
    3 days ago
    Total: 52s
    #474214
Production build 0.71.5 2024