Preferences

>it's the only way of "code" reuse, really.

not really. You can also use include/extends pattern. If that is not enough, there is dynamic pipeline generation feature.


In my experience include/extends works well for importing or extending whole jobs, but not so much for defining a small snippet of text that I want to reuse across many jobs, perhaps when overriding stuff.

An example of how I normally use them and why I still find them useful:

  # Imports whole pipeline architecture jobs
  include:
  - project: company/ci-templates
    ref: "master"
    file: "languages/stack.yaml"
  
  # Define a command I need to use exactly the same
  # across different jobs I'm going to override
  .vpn_connect: &vpn_connect
    - cmd1
    - cmd2
    - cmd3 &
  
  job1:
    extends: imported1
    script:
      - ....
      - *vpn_connect # 2nd command
      - ...
  
  job2:
    extends: imported2
    script:
      - ...
      - ...
      - *vpn_connect # 3rd command
      - ...
> include

Interesting, although to me it looks more like a way to split one file into several (which is rather useful).

> extends

What's the difference with anchors? Looks the same, except works with include (and doesn't work with any other yaml tool).

> dynamic pipeline generation

Which is even harder to reason about compared to anchors, although certainly powerful.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal