# Can I assign a CI variable on the parallelism value?

**URL:** <https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204>\
**Category:** General\
**Created:** [September 1, 2022, 10:15am UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204 "2022-09-01T10:15:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebanster](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@ebanster](https://forum.buildkite.community/u/ebanster)\
**Post date:** [September 1, 2022, 10:15am UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/1 "2022-09-01T10:15:32Z")

</div>

Let’s say I have this step on the Build steps:

```auto
steps:
  - label: 'Run tests'
    commands: 'make run_tests'
    parallelism: 4

```

Can I make the value (e.g. 4) on `parallelism` as a variable like ${PARALLEL\_RUN}?

so it looks like something like this:

```auto
env:
  PARALLEL_RUN: 4

steps:
  - label: 'Run tests'
    commands: 'make run_tests'
    parallelism: ${PARALLEL_RUN}

```

Ultimately, this pipeline is a triggered pipeline from other repositories so I would like to have more flexibility in terms of running the jobs in parallel depending on the codebase’s pipeline running.

---

<div class="post-metadata">

**Author:** ![suma](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/suma/32/1306_2.png) [@suma](https://forum.buildkite.community/u/suma)\
**Post date:** [September 1, 2022, 5:21pm UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/2 "2022-09-01T17:21:37Z")

</div>

Hi @ebanster

No, we cannot use variable interpolation for parallelism and only option here is to use dynamic pipeline where you can use environment variable to define the parallelism for the pipeline definition which will be uploaded using the dynamic pipeline process.

---

<div class="post-metadata">

**Author:** ![ebanster](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@ebanster](https://forum.buildkite.community/u/ebanster)\
**Post date:** [September 1, 2022, 10:41pm UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/3 "2022-09-01T22:41:35Z")

</div>

Thanks @suma can you show me an example on how this dynamic pipeline can be done?

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [September 1, 2022, 10:53pm UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/4 "2022-09-01T22:53:11Z")

</div>

Hey @ebanster!

You can check our docs that have a complete explanation of how dynamic pipeline works [Defining Your Pipeline Steps | Buildkite Documentation](https://buildkite.com/docs/pipelines/defining-steps#dynamic-pipeline-templates), and you can check a working example here [GitHub - buildkite/dynamic-pipeline-example: An example of how to generate dynamic build pipelines in Buildkite](https://github.com/buildkite/dynamic-pipeline-example)

Best!

---

<div class="post-metadata">

**Author:** ![vlad.voelk](https://avatars.discourse-cdn.com/v4/letter/v/f05b48/32.png) [@vlad.voelk](https://forum.buildkite.community/u/vlad.voelk)\
**Post date:** [September 2, 2022, 7:16am UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/5 "2022-09-02T07:16:52Z")

</div>

@ebanster  
you could use YAML anchor/alias instead  
here is an example

```auto
global_vars:
  - &PARALLEL_RUN
  	4

steps:
  - label: 'Run tests'
    commands: 'make run_tests'
    parallelism: <<: *PARALLEL_RUN

```

---

<div class="post-metadata">

**Author:** ![ebanster](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@ebanster](https://forum.buildkite.community/u/ebanster)\
**Post date:** [November 28, 2022, 11:35pm UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/6 "2022-11-28T23:35:03Z")

</div>

I transferred the CI steps into the yaml file instead but I still get an error on the yaml file that its expecting an integer.  
On my `pipeline.yaml` file, both these gives me the ‘integer’ error:

```auto
steps:
  - label: 'Run tests'
    commands: 'make run_tests'
    parallelism: ${PARALLEL_RUN} # integer value tried to be passed from CI variable

```

```auto
global_vars:
  - &PARALLEL_RUN
    4

steps:
  - label: 'Run tests'
    commands: 'make run_tests'
    parallelism: <<: *PARALLEL_RUN

```

---

<div class="post-metadata">

**Author:** ![lizette](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/lizette/32/1161_2.png) [@lizette](https://forum.buildkite.community/u/lizette)\
**Post date:** [November 29, 2022, 7:27am UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/7 "2022-11-29T07:27:46Z")

</div>

Hi @ebanster,

As mentioned in the earlier reply, we cannot use variable interpolation for parallelism. Therefore, the suggested use of YAML anchor/alias will still give you the same errors.

Posting back here the suggestion earlier.

> [@paula](#):
>
> Hey @ebanster!
> 
> You can check our docs that have a complete explanation of how dynamic pipeline works [Defining Your Pipeline Steps | Buildkite Documentation](https://buildkite.com/docs/pipelines/defining-steps#dynamic-pipeline-templates), and you can check a working example here [GitHub - buildkite/dynamic-pipeline-example: An example of how to generate dynamic build pipelines in Buildkite](https://github.com/buildkite/dynamic-pipeline-example)
> 
> Best!

Cheers,  
Lizette

---

<div class="post-metadata">

**Author:** ![ebanster](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@ebanster](https://forum.buildkite.community/u/ebanster)\
**Post date:** [November 29, 2022, 10:20pm UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/8 "2022-11-29T22:20:48Z")

</div>

Hi @lizette Thanks. Would you know if it only recognises a shell script?  
Instead of using a shell script (`pipeline.sh`), we are using a Makefile. I tried to include it with the following:

```auto
run_tests: .env
	echo " - label: 'Run tests'"
	echo " command: 'make run_tests'"
	echo " parallelism: ${BUILDKITE_PARALLELISM}"
.PHONY: run_tests

```

Then on my `pipeline.yml` I have:

```auto
steps:
  - label: 'Run tests'
    command: 'make run_tests'

```

---

<div class="post-metadata">

**Author:** ![lizette](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/lizette/32/1161_2.png) [@lizette](https://forum.buildkite.community/u/lizette)\
**Post date:** [November 30, 2022, 3:21am UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/9 "2022-11-30T03:21:12Z")

</div>

Hi @ebanster,

The example you provided will just echo the steps into the terminal. The steps won’t be executed by the Buildkite Agent as you would expect. I believe the only way to do this is to create a YAML file, pass it on to the agent and use the buildkite-agent pipeline upload command.

Here’s a sample snippet:

In your pipeline steps:

```auto
env:
   PARALLEL_RUN: 3

steps:
- label: ":Run steps:"
  command: pipeline.sh | buildkite-agent pipeline upload

```

In your pipeline.sh

```auto
cat <<YAML
steps:
- command: echo This is a dynamic step
  label: "Test %n"
  parallelism: ${PARALLEL_RUN}
YAML

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![ebanster](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@ebanster](https://forum.buildkite.community/u/ebanster)\
**Post date:** [December 4, 2022, 12:55pm UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/10 "2022-12-04T12:55:34Z")

</div>

Thanks @lizette this worked!

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [August 29, 2023, 5:39am UTC](https://forum.buildkite.community/t/can-i-assign-a-ci-variable-on-the-parallelism-value/2204/11 "2023-08-29T05:39:29Z")

</div>


