Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the symbols *1 or &2 mean in Travis CI deployment scripts?

Tags:

travis-ci

I'm following the guide for using Travis to deploy to AWS CodeDeploy. In those docs they point to a .travis.yml example which contains the following code:

deploy:
  - provider: s3
    access_key_id: AKIAJ4XZHIMNKP3WGGHQ
    secret_access_key: &1
      secure: <key>
    local_dir: dpl_cd_upload
    skip_cleanup: true
    on: &2
      repo: travis-ci/cat-party
    bucket: catparty-codedeploy
  - provider: codedeploy
    access_key_id: AKIAJ4XZHIMNKP3WGGHQ
    secret_access_key: *1
    bucket: catparty-codedeploy
    key: latest.zip
    bundle_type: zip
    application: CatPartyDemoApplication
    deployment_group: ProductionDemoFleet
    on: *2

I've got this working and understand the flow (first it uploads the zip file to S3, then it deploys that file to CodeDeploy). What I'm struggling with is the syntax: specifically the on: &2 line in the s3 section, and the on: *2 part in the codedeploy section. What are these lines doing?

I ask because I want to modify this configuration to deploy to a different CodeDeploy group depending on whether the commit has a given tag, eg:

on:
  tags: true
  all_branches: true
  condition: "$TRAVIS_TAG =~ ^release.*$"

... but because I'm not clear what the on: *2 is doing (and can't find it in the docs), I'm uncertain how to proceed. Any tips?

like image 415
Matt Andrews Avatar asked Feb 05 '23 17:02

Matt Andrews


1 Answers

Those symbols and the features they bring are part of YAML itself. They're supported to reduce duplication efforts in a YAMl file.

For instance, this section prefixed with the & stores the subsequent structure as a reference with the name 2. So 2 now references repo: travis-ci/cat-party.

on: &2 repo: travis-ci/cat-party

The reference name can also be a an alphanumeric set of characters to make things more expressive.

On the other hand, * is then used to resolve that reference where you want to reuse it.

So in the following section the YAML parser would resolve the *2 to the structure previously stored: repo: travis-ci/cat-party:

on: *2

This feature saves you duplication, which can be handy in several aspects of a .travis.yml file.

like image 163
roidrage Avatar answered Apr 30 '23 06:04

roidrage