Specifying "strategy" in workflow defaults

I’m trying to use the same strategy across all jobs in a workflow:

name: My Workflow
defaults:
  strategy:
    matrix:
      node: [8, 10, 12]
jobs:
  ...

but this fails with Unexpected value ‘strategy’. Is this supposed to work, or is “run” the only default that can be specified?

1 Like

@zbjornson ,

Yeah, this is not supported in the GitHub Actions workflow.

The strategy is used to create a build matrix for a job, it is a job-level syntax, and you can’t use it on workflow-level to configure all the jobs at once in the workflow.

If you want to configure the same matrix for all jobs in the workflow, you need to configure on every job.

Of course, if your projects really need this feature, I recommend you directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

Thanks. The way the docs are worded (“A map of default settings that will apply to all jobs in the workflow”) it sounded like this was a base job config where any job parameter could be specified, and each job extended that base config. Imagine also the use case of specifying defaults.runs_on to specify an OS for all jobs.

@zbjornson ,

The " defaults" syntax is a new feature released recently. Currently, it only supports to set the default options for run steps. We can’t use this syntax to set matrix for all jobs in the workflow.

If your projects really need this feature, I recommend you directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

@brightran I second this limitation.
Say in the above example the strategy matrix is placed correctly within the first job, e.g. ‘test’ and the matrix uses in this case node version of {{ matrix.node }} value in test stage. Now if I set a second job, say ‘build’, after the first and add needs dependency on [test]. Ideally if ‘test’ stage passes on all 3 matrix jobs, it should run all 3 corresponding ‘build’ jobs following the passing ‘test’ jobs, or run on 2 of the 3 if 2 pass and 1 fail.

But the bug of GitHub actions is that the ‘build’ job is going to run following the last job in the matrix, i.e. with node 12 and if that ‘test’ job fails not a single one is going to be run.