I am trying to test and build for multiple operating systems and so I use a matrix that looks something like this
workflows:
all-tests:
jobs:
- test:
matrix:
parameters:
os: [linux, macos, windows]
Where os is an executor.
jobs:
test:
parameters:
os:
type: executor
But for each one I want to do conditional setup steps based on the executor type and I couldn’t find a way to do that.
I tried:
condition:
equal: [ macos, << parameters.os >> ]
but the condition is never true as << paramaters.os >> seems to be converted into an executor object string and so it is not the same as macos even when the executor type is called macos.
How can I achieve something like this?
Thanks!
Hi @csreesan
I have a sample config.yml file that might be useful to reference.
It can also be viewed at: Conditional executor config · GitHub
version: 2.1
executors:
linux:
docker:
- image: cimg/base:2020.01
mac:
macos:
xcode: "11.3.0"
win:
machine:
image: windows-server-2019-vs2019:stable
resource_class: windows.medium
shell: powershell.exe
jobs:
test:
parameters:
os:
type: string
executor: <<parameters.os>>
steps:
- checkout
- run: echo "test"
workflows:
all-tests:
jobs:
- test:
matrix:
parameters:
os: ["linux", "mac", "win"]
In the above, I am defining three executors, “linux”, “mac”, and “windows”.
Then I set the executor for the job to equal the name of the executor being passed in by the pipeline variable “os”. This will run the job test for each executor named in the matrix.
For more information regarding executors and conditional workflows, please take a look at the following sections in our documentation:
https://circleci.com/docs/2.0/reusing-config/#using-the-parameters-declaration
https://circleci.com/docs/2.0/reusing-config/#example-of-using-an-executor-declared-in-configyml-with-matrix-jobs
Let me know if this helps.
Thank you! That solves my problem!