title: How to merge sequences in .gitlab-ci.yml?
body: <p>I am trying to remove some redundancy in setting up several tasks within GitLab CI. As a (greatly) simplified example, I have two jobs involving a call to <code>apt-get update</code>:</p>
  
  <pre><code>job1:
    before_script:
      - apt-get update
      - apt-get install foo
  
  job2:
    before_script:
      - apt-get update
      - apt-get install bar
  </code></pre>
  
  <p>Not being a big fan of repetitions, I hoped that I would be able to "clean up" the yaml through the help of <a href="https://gitlab.com/help/ci/yaml/README.md#anchors" rel="noreferrer">anchors</a> as follows:</p>
  
  <pre><code>.update: &amp;update
    before_script:
      - apt-get update
  
  job1:
    &lt;&lt;: *update
    before_script:
      - apt-get install foo
  
  job2:
    &lt;&lt;: *update
    before_script:
      - apt-get install bar
  </code></pre>
  
  <p>However, it appears that the <code>before_script</code> stanzas are not merged with <code>*update</code>. Instead, I find latter one being <em>overwritten</em>. This is in contrast to the GitLab CI docs as well as the example on <a href="https://en.wikipedia.org/wiki/YAML#Advanced_components" rel="noreferrer">Wikipedia</a>, though.</p>
  
  <p>Through some experimentation, I managed to get the following to run:</p>
  
  <pre><code>.update: &amp;update apt-get update
  
  job1:
    before_script: 
      - *update
      - apt-get install foo
  
  job2:
    before_script: 
      - *update
      - apt-get install bar
  </code></pre>
  
  <p>Clearly a step forward. But given that I intend to go for more complex substitutions, this is hardly satisfactory. For reference: This is on GitLab v 8.12.</p>