Dynamic matrix values

I’m trying to sort out a way to deploy to multiple regions using a dynamic list of regions that can be shared across multiple projects that are using semaphore.

I’ve tried using a job matrix with the values coming from a secret:

Secret:

data:
  env_vars:
  - name: MATRIX_REGIONS
    value: region1, region2, region3

Promtion:

      secrets:
        - name: regions
      jobs:
      - name: Deploy to regions
        matrix:
          - env_var: REGION
            values: [ $MATRIX_REGIONS ]
        commands:
          - deploy $REGION

This doesn’t work since the environment variable is just a string so $REGION is coming through as “region1, region2, region3”.

Is there another approach I can take to implement this? We could hard code the regions into the values for each of our promotions, but we have a good number of projects that need the same logic and the regions change regularly.

1 Like

Hi there,

Currently, secrets can’t hold an array of values as shown in the matrix job example. This is an interesting use case and to make it work using the matrix job it is only possible to hardcode the values as detailed in the matrix job docs page.
The reason being the matrix does not pick up global environment variables since it is not an actual part of the job. The variables from the secret get injected once the job starts but the matrix is defined before this step.
Nevertheless, I do see the value of this feature so I have created a feature request based on your use case and shared it with the team. To make secrets hold arrays.

Best regards,