Sequential workflows running the same job with different parameters

I’ve recently spent some time rewriting our CircleCI configurations. One thing that keeps me from writing a truly DRY config again and again is this:

workflows:
    my-workflow:
        jobs:
           - my-special-job
                my-param: subjectA

           - my-special-job
                my-param: subjectB
                requires:
                     - my-special-job<¿¿¿WITH my-param: subjectA???>

I initially didn’t think twice about this, as I was assuming I could simply use Alias indicators,

-my-special-job: &variant1
    ...

-my-special-job
   ....
   requires:
      - *variant1

but that doesn’t seem to work.

Does anyone have a solution to this?
I would hate to keep duplicating jobs with hardcoded params and slightly different names for something as simple as this.

1 Like

The matrix stanza allows you to run a parameterized job multiple times with different arguments. This video also does a good job of walking you through how Matrix in CircleCI works.
Matrix Jobs on CircleCI

1 Like

With the help of Henna’s pointers I ended up solving my issue without using matrixes, but I’m glad to have learned about them for possibly making my configuration even more DRY in the future.

The solution was quite simple. In the workflow section, jobs with different params can be uniquely referenced by adding a name property. That alone solved my problem. I.e.

workflows:
    my-workflow:
        jobs:
           - my-special-job
                name: special-job-for-A
                my-param: subjectA

           - my-special-job
                my-param: subjectB
                requires:
                     - special-job-for-A

Hopefully that will help someone in the future.

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.