Adding name: changes build jobs

build-stages
env-vars
stages
#1

Goal

I’m aiming for a build matrix like this:

Test stage:

    1 Primary tests      MY_VAR=abc
    2 Primary tests      MY_VAR=def
    3 Other tests

Docker build & push stage:

    4  Build & publish docker images

It doesn’t matter if there’s a MY_VAR for jobs 3 or 4.

Without name:

I’ve got it working with a .travis.yml something like this (the real one is in a private repo):

language: php

services:
- mysql
- docker

php:
  - 7.3

matrix:
  fast_finish: true

env:
  global:
    - COMPOSER_BIN=$TRAVIS_BUILD_DIR/vendor/bin
    - BLT_DIR=$TRAVIS_BUILD_DIR/vendor/acquia/blt
    - BUILD_DIR=$TRAVIS_BUILD_DIR
    - SIMPLETEST_DB=mysql://drupal:drupal@localhost/drupal
    - SIMPLETEST_BASE_URL=http://127.0.0.1:8888
    - SYMFONY_DEPRECATIONS_HELPER=weak
    - SERVICE_NAME=$(basename $TRAVIS_REPO_SLUG)
    - NGINX_DOCKER_IMAGE=$SERVICE_NAME-nginx:$VERSION_NUMBER
    - PHP_DOCKER_IMAGE=$SERVICE_NAME:$VERSION_NUMBER
    - PATH=~/bin:$PATH
  matrix:
    - MY_VAR=abc
    - MY_VAR=xyz

jdk:
  - oraclejdk8

cache:
  bundler: true
  apt: true
  pip: true
  directories:
  - "$HOME/.composer/cache"
  - "$HOME/.drush/cache"
  - "$HOME/.npm"
  - "$HOME/.nvm"
  - ".rules"

addons:
  ssh_known_hosts:
  # - svn-4786.devcloud.hosting.acquia.com
  chrome: stable

before_install:
  - echo "Primary tests"
  - echo before_install
  - echo before_install
  - echo before_install
  - echo before_install
  - echo before_install
  - echo before_install

stage: "Test"
install:
  - echo "Primary tests"
  - echo install
  - echo install
  - echo install

script:
  - echo "Primary tests"
  - echo script
  - echo script
  - echo script
  - echo script
  - echo script
  - echo script
  - echo script
  - echo script
  - echo script
  - echo script
  - echo script
  - echo script
  - echo script

after_success:
  - echo "Primary tests"
  - echo after_success
  - echo after_success
  - echo after_success
  - echo after_success
  - echo after_success
  - echo after_success
  - echo after_success
  - echo after_success
  - echo after_success

jobs:
  include:
    - stage: "Test"
      install:
        - echo "Secondary tests"
        - echo install

      script:
        - echo "Secondary tests"
        - echo script
        - echo script
        - echo script

      after_success:
        # Don't inherit global after_success
        - echo ""

    - stage: "Docker build & push"
      before_install:
        - echo "Build & publish Docker images"
        - echo before_install
        - echo before_install
        - echo before_install

      script:
        - echo "Build & publish Docker images"
        - echo script
        - echo script

https://travis-ci.org/hugovk/test/builds/518681981

With name:

However, if I add name: values for clarity in the UI:

 .travis.yml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index c047d5a..78d56bd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -55,6 +55,7 @@ before_install:
   - echo before_install
 
 stage: "Test"
+name: "Primary tests"
 install:
   - echo "Primary tests"
   - echo install
@@ -92,6 +93,7 @@ after_success:
 jobs:
   include:
     - stage: "Test"
+    - name: "Secondary tests"
       install:
         - echo "Secondary tests"
         - echo install
@@ -107,6 +109,7 @@ jobs:
         - echo ""
 
     - stage: "Docker build & push"
+      name: "Build & publish Docker images"
       before_install:
         - echo "Build & publish Docker images"
         - echo before_install
-- 
2.21.0

It adds an extra, unnecessary build job. The highlighted 319.3 is “Primary tests” with MY_VAR=abc, just like 319.1:

https://travis-ci.org/hugovk/test/builds/518686318

Questions

Am I missing something, or doing something wrong?

Is this a bug?

Is there another way to label the jobs?

Thank you!

#2

Your jobs.include has an extra element in the array because you have a - in front of the name line you added.

What you want is:

jobs:
  include:
    - stage: "Test"
      name: "Secondary tests"
      ⋮
    - stage: "Docker build & push"
      name: "Build & publish Docker images"
      ⋮
#3

Thank you for the quick reply, that fixed it!