Complex Multi-Job Matrix with Conditional Deploys Fails on Secret Merging – Need Advanced Debugging Help

The goal of my current setup is to run multiple Python versions (3.8, 3.9, and 3.10) as part of a test matrix. I want only one of these jobs—specifically the one using Python 3.10—to trigger a deploy step once the tests pass and the branch is main. I’m using the stages feature to separate testing and deployment.

Despite deploy being limited to the last stage, Travis tries to run it on all matrix jobs unless I manually hack around it. When I use:

deploy:
  provider: script
  script: ./scripts/deploy.sh
  on:
    branch: main
    condition: $TRAVIS_PYTHON_VERSION = "3.10"

Here’s a shortened version of my .travis.yml:

language: python
python:
  - "3.8"
  - "3.9"
  - "3.10"

stages:
  - test
  - name: deploy
    if: branch = main AND type != pull_request AND python = "3.10"

jobs:
  include:
    - stage: test
      script: pytest tests/
    - stage: deploy
      script: ./scripts/deploy.sh

Hi @talisman,

You need to use stages with conditional logic and avoid placing deploy: at the root of .travis.yml. Instead, define deploy as a job inside the jobs.include section with a stage: deploy label and use if: to control it.

For example:

stages:
  - test
  - name: deploy
    if: branch = main AND type != pull_request

jobs:
  include:
    - python: "3.8"
      stage: test
      script: pytest

    - python: "3.9"
      stage: test
      script: pytest

    - python: "3.10"
      stage: test
      script: pytest

    - stage: deploy
      if: branch = main AND type != pull_request AND python = "3.10"
      script: ./scripts/deploy.sh

Skip deploy if secrets are not set early on in the build:

[ -z "$MY_SECRET_TOKEN" ] && echo "No secret available, skipping deploy." && exit 0

This should handle it, this is a bit more complex case you’re correct. This should get your build working again though.