# Parametric machine\_type\_id

**URL:** <https://discuss.bitrise.io/t/parametric-machine-type-id/22407>\
**Category:** Question & Answer\
**Created:** [March 22, 2023, 12:30pm UTC](https://discuss.bitrise.io/t/parametric-machine-type-id/22407 "2023-03-22T12:30:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierre-emmanuel.alti](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@pierre-emmanuel.alti](https://discuss.bitrise.io/u/pierre-emmanuel.alti)\
**Post date:** [March 22, 2023, 12:30pm UTC](https://discuss.bitrise.io/t/parametric-machine-type-id/22407/1 "2023-03-22T12:30:33Z")

</div>

Hello there,

Is it possible to use a variable as machine\_type\_id for a workflow?

I would like to do something like this (where MACHINE\_TYPE\_ID is set to standard / elite machine type id):

```auto
  dynamic-stack-workflow:
    - step1
      (...)
    meta:
      bitrise.io:
        stack: linux-docker-android-20.04
        machine_type_id: ${{ MACHINE_TYPE_ID }}

```

But it gives me the following error:  
Error saving app config: Invalid machine type for workflow: ‘dynamic-stack-workflow’.

Is this even possible?

---

<div class="post-metadata">

**Author:** ![Leilah.squires](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/leilah.squires/32/4845_2.png) [@Leilah.squires](https://discuss.bitrise.io/u/Leilah.squires)\
**Post date:** [March 22, 2023, 3:46pm UTC](https://discuss.bitrise.io/t/parametric-machine-type-id/22407/2 "2023-03-22T15:46:08Z")

</div>

Hi @pierre-emmanuel.alti Thanks for posting your question!

No, unfortunately it is not possible to use a variable as machine\_type\_id for a workflow. The machine\_type\_id must be set to a specific machine type id, such as standard or elite.

Do you mind sharing why you want to use a variable instead? What is the end goal you are trying to achieve?

Thanks again,  
Leilah

---

<div class="post-metadata">

**Author:** ![pierre-emmanuel.alti](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@pierre-emmanuel.alti](https://discuss.bitrise.io/u/pierre-emmanuel.alti)\
**Post date:** [March 24, 2023, 10:37am UTC](https://discuss.bitrise.io/t/parametric-machine-type-id/22407/3 "2023-03-24T10:37:47Z")

</div>

Hi Leilah, and thank you for your answer.

What I’m working on is what I call a dynamic stack step:

- We are running a unit tests and quality checks pipeline for every pull request we open.
- Our pipeline uses key based cache, and the keys are partly based on the name of the source branch.

It means that when we open a PR, the cache does not exist yet for this specific branch (it actually falls back to the main branch cache), so the first execution is a bit slower than when the cache is available.

I have made a step that uses [your API](https://devcenter.bitrise.io/en/api/api-reference.html) to check if any cache key corresponds to this specific branch. This step can be run as the entry point of our check pipeline, it’s only taking a few seconds.

What I would like to do now, is to run the check build workflows on a elite or eliteXL machine if the cache does not exist. If the cache exists, I want to run it on a standard machine.

---

<div class="post-metadata">

**Author:** ![Leilah.squires](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/leilah.squires/32/4845_2.png) [@Leilah.squires](https://discuss.bitrise.io/u/Leilah.squires)\
**Post date:** [March 27, 2023, 5:56pm UTC](https://discuss.bitrise.io/t/parametric-machine-type-id/22407/4 "2023-03-27T17:56:06Z")

</div>

Firstly I want to share how much of a good idea this is for optimizing for shorter build times 👏🏽 👏🏽 👏🏽

So based on my understanding, your step checks first is there is a cache associated with the branch. If not, the main branch cache will run and in that case you want to run it on the Elite machines. If thats correct, can you try the following in your step:

```auto
#!/bin/bash

# Get the name of the branch
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)

# Check if the branch name is in the key based cache
if bitrise cache:pull --key "$BRANCH_NAME"; then
  # Run the build on the Standard machine
  bitrise run --machine-type standard
else
  # Run the build on the EliteXL machine
  bitrise run --machine-type elitexl
fi"

```

Let me know if this was helpful or if you need additional help troubleshooting (in the case I completely misunderstood what you are trying to do ha ha).

---

<div class="post-metadata">

**Author:** ![pierre-emmanuel.alti](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@pierre-emmanuel.alti](https://discuss.bitrise.io/u/pierre-emmanuel.alti)\
**Post date:** [March 29, 2023, 4:21pm UTC](https://discuss.bitrise.io/t/parametric-machine-type-id/22407/5 "2023-03-29T16:21:02Z")

</div>

Hi Leilah,

Thank you for your feedback and your answer. You got it, it’s exactly what I’m trying to do.

So I’ve tried your solution by running a simple workflow within a step by a bash script:

From the bitrise.yml file:

```auto
workflows:
  test-dispatch:
    steps:
    - script:
        inputs:
        - title: Dispatch run test
        - content: |-
            #!/bin/bash

            ## Attempt 1 like you mentioned
            bitrise run --machine-type standard

            ## Attempt 2, adding test-dispatch-run
            bitrise run --machine-type standard test-dispatch-run
        
  test-dispatch-run:
    steps:
    - script:
        (...)

```

But in both cases, I have the following error:

```auto
+ bitrise run --machine-type standard test-dispatch-run
Incorrect Usage: flag provided but not defined: -machine-type
NAME:
   bitrise run - Runs a specified Workflow.
USAGE:
   bitrise run [command options] [arguments...]
OPTIONS:
   --workflow value workflow id to run.
   --config value, -c value Path where the workflow config file is located.
   --inventory value, -i value Path of the inventory file.
   --secret-filtering Hide secret values from the log.
   --json-params value Specify command flags with json string-string hash.
   --json-params-base64 value Specify command flags with base64 encoded json string-string hash.
   --output-format value Log format. Available values: json, console
   --path value, -p value [Deprecated!!! Use 'config'] Path where the workflow config file is located.
   --config-base64 value base64 encoded config data.
   --inventory-base64 value base64 encoded inventory data.
   
flag provided but not defined: -machine-type

```

And indeed, even locally, I’ve tried to update Bitrise CLI to the latest version but it seems that this option --machine-type is not available.

I must have misunderstood something, or perhaps you’re using an internal version ?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![atanas-bitrise](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@atanas-bitrise](https://discuss.bitrise.io/u/atanas-bitrise)\
**Post date:** [October 3, 2023, 1:26pm UTC](https://discuss.bitrise.io/t/parametric-machine-type-id/22407/6 "2023-10-03T13:26:19Z")

</div>

Hello,

The `bitrise run` command cannot be used in this way. Generally, the CLI cannot be used to select the machine type because it is running on a machine already.

However, one of the Bitrise APIs can be used instead

```auto
curl https://app.bitrise.io/app/[app]/build/start.json -L --data '{"build_params":{"branch":"pipelines","workflow_id":"primary","machine_type_id":"g2-m1.8core","stack":"osx-xcode-14.3.x-ventura"},"hook_info":{"build_trigger_token":"[token]","type":"bitrise"},"triggered_by":"curl"}'

```

vs

```auto
curl https://app.bitrise.io/app/[app]/build/start.json -L --data '{"build_params":{"branch":"pipelines","workflow_id":"primary","machine_type_id":"g2-m1-max.10core","stack":"osx-xcode-14.3.x-ventura"},"hook_info":{"build_trigger_token":"[token]","type":"bitrise"},"triggered_by":"curl"}'

```

The `--machine-type` parameter is not a valid CLI parameter.

I hope that this helps.

Best,
