# Running 'n' steps in parallel

**URL:** <https://community.codefresh.io/t/running-n-steps-in-parallel/776>\
**Category:** Pipeline Workflows\
**Created:** [May 4, 2022, 5:39am UTC](https://community.codefresh.io/t/running-n-steps-in-parallel/776 "2022-05-04T05:39:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![manishjainctr](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/manishjainctr/32/494_2.png) [@manishjainctr](https://community.codefresh.io/u/manishjainctr)\
**Post date:** [May 4, 2022, 5:39am UTC](https://community.codefresh.io/t/running-n-steps-in-parallel/776/1 "2022-05-04T05:39:38Z")

</div>

We have the feature of running steps in parallel ([Advanced Workflows with Parallel steps · Codefresh | Docs](https://codefresh.io/docs/docs/codefresh-yaml/advanced-workflows/#inserting-parallel-steps-in-a-sequential-pipeline)). In this case, the number of steps we want to run is known in advance.  
I have a scenario where the number of steps I want to run in parallel is dynamic, calculated via an API call to be precise, something like:

```auto
version: '1.0'
steps:
  GetInfo:
    title: Get list of files
    image: alpine
    commands: 
          - some logic to get the list_of_files; list might have 1 or many files
          - export list_of_files to be usable in subsequent steps
  WritingInParallel:
    type: parallel
    steps:
      writing_file_n:
        title: Step_n
        image: alpine
        commands: 
          - echo "Step_n" > list_of_files[n]

```

Somehow, I wish to run n (number of file in list\_of\_files) parallel steps here. Is there a way of doing it using parallel or scale method or any other method?

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [May 9, 2022, 7:27am UTC](https://community.codefresh.io/t/running-n-steps-in-parallel/776/2 "2022-05-09T07:27:55Z")

</div>

Hello @manishjainctr

No, currently this is not supported. Pipelines do not support changing the number of steps in the middle of the pipeline.

Please open a feature request with our support team. They might also offer some workarounds for this.

---

<div class="post-metadata">

**Author:** ![manishjainctr](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/manishjainctr/32/494_2.png) [@manishjainctr](https://community.codefresh.io/u/manishjainctr)\
**Post date:** [May 19, 2022, 9:33am UTC](https://community.codefresh.io/t/running-n-steps-in-parallel/776/3 "2022-05-19T09:33:25Z")

</div>

If ‘n’ nubmer of step is possible in parallel, Is there any way to run ‘n’ step sequentially.

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [May 24, 2022, 8:59am UTC](https://community.codefresh.io/t/running-n-steps-in-parallel/776/4 "2022-05-24T08:59:59Z")

</div>

You could use a custom plugin to run a dynamic number of steps sequentially [https://codefresh.io/docs/docs/codefresh-yaml/steps/#example-with-step-templating](https://codefresh.io/docs/docs/codefresh-yaml/steps/#example-with-step-templating)

But they will still appear as a single box in the UI.

---

<div class="post-metadata">

**Author:** ![mlebarron](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/mlebarron/32/504_2.png) [@mlebarron](https://community.codefresh.io/u/mlebarron)\
**Post date:** [May 31, 2022, 5:19pm UTC](https://community.codefresh.io/t/running-n-steps-in-parallel/776/5 "2022-05-31T17:19:05Z")

</div>

I have a similar issue where we have an Nx monorepo and I’m not sure how many “apps” I need to build until a step runs. What I do is setup a new pipeline that gets triggered N number of times based on the output from Nx.

I have a step that builds a yaml file that I feed to [Codefresh | codefresh-run-dynamic step](https://codefresh.io/steps/step/codefresh-run-dynamic)

```auto
      for APP_NAME in $AFFECTED_APPS;
      do
      {
          echo "- pipeline_id: core/app-pipeline"
          echo " trigger_id: trigger-as-child"
          echo " branch: $CF_BRANCH"
          echo " sha: $CF_REVISION"
          echo " variables:"
          echo " APP_NAME: $APP_NAME"
      } >> "/codefresh/volume/$CF_BRANCH_TAG_NORMALIZED_LOWER_CASE/trigger-app-pipeline.yaml";

```

then

```auto
  runPipelines:
    title: Trigger app pipelines
    stage: deploy
    type: codefresh-run-dynamic
    arguments:
      RUN_LIST_YAML_FILE: /codefresh/volume/${{CF_BRANCH_TAG_NORMALIZED_LOWER_CASE}}/trigger-app-pipeline.yaml
      LOG_DIRECTORY: /codefresh/volume/${{CF_BRANCH_TAG_NORMALIZED_LOWER_CASE}}/run-logs

```

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [June 1, 2022, 10:03am UTC](https://community.codefresh.io/t/running-n-steps-in-parallel/776/6 "2022-06-01T10:03:22Z")

</div>

Thanks for the tip @mlebarron

That is also another great approach @manishjainctr that you can use.
