How to include several anchors in a single key value?

Viewed 97

I'm trying to set up some GitLab CI jobs that rely on a common set of files. Basically, I've got 2 lists, and 3 jobs:

.list1: 
  only:
    changes: &list1
      - file1
      - file2
      
.list2: 
  only:
    changes: &list2
      - file3
      - file4
      
      
job1:
  only:
    changes: *list1
    
job2:
  only:
    changes: *list2
    
job3:
  only:
    changes:
    # How can I include list1 and list2????
  

Currently the only way I seem to be able to work this is to manually list all of the files in job 3, which means I'm maintaining the same list in 2 places. Can I include both lists somehow?

1 Answers

Using the CI linter, I found the following appeared to work:

.list1:
  only: 
    changes: &list1 
      file1 ,
      file2

.list2:
  only: 
    changes: &list2 
      file3 ,
      file4


job:
  script:
    - echo "Hello"
  only:
    changes: [ *list1, *list2 ]
Related