Skip to content

GitLab Next

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
GitLab
GitLab
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 36,069
    • Issues 36,069
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 1,299
    • Merge Requests 1,299
  • Requirements
    • Requirements
    • List
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Metrics
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.org
  • GitLabGitLab
  • Issues
  • #23005

Closed
Open
Created Jun 27, 2018 by Damian Nowak@NowakerContributor

Simplify includes by flattening before_script, script and after_script arrays

Description

Wouldn't this make everyone's life with gitlab-ci.yml easy and fun?

.something: &something
- echo something
- ./dosomething

.somethingelse: &somethingelse
- echo somethingelse
- ./dosomethingelse

job1:
  script:
  - *something
  - echo job1

job2:
  script:
  - *something
  - *somethingelse
  - echo job2

At first, it sounds looks perfectly fine and reasonable. Why wouldn't it work?

But then one realizes it won't work because the array isn't flat anymore. The output object is the below - and nested arrays are problematic:

{job1: {script: [['echo something', './dosomething'], 'echo job1']}, job2: {script: [['echo something', './dosomething'], ['echo somethingelse', './dosomethingelse'], 'echo job2'}}

Proposal

Flatten the hell out of before_script, script, after_script and make life easy!

{script: [['echo something', './dosomething'], 'echo job1']} -> {script: ['echo something', './dosomething', 'echo job1']}

Limitations

This will work with anchor syntax, but not with the extends keyword.

Workaround

@ayufan proposed a workaround: https://gitlab.com/gitlab-org/gitlab-ce/issues/19677#note_13008199

.bundle_install: &bundle_install |
  echo aa
  echo bb

.bundle_exec: &bundle_exec |
  echo aa
  echo bb

test:
  script:
  - *bundle_install
  - *bundle_exec

The | syntax is a way to write a single command but appear as multi-line in YAML. The runner treats it as a single bash command. In other words, it's equivalent to running echo aa && echo bb- and this is an inferior solution since when the job fails on a very long multi-line statement it's not clear which command failed.

Links to related issues and merge requests / references

https://gitlab.com/gitlab-org/gitlab-ce/issues/19677

CC @ayufan @grzesiek @markpundsack @bikebilly @markglenfletcher

Edited Oct 16, 2019 by Jason Yavorska
Assignee
Assign to
12.5
Milestone
12.5 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: gitlab-org/gitlab#23005