# Setting a job parameter default to another parameter fails silently

**URL:** <https://discuss.circleci.com/t/setting-a-job-parameter-default-to-another-parameter-fails-silently/45035>\
**Category:** Bug Reports\
**Tags:** circle-yml, 21\
**Created:** [August 11, 2022, 5:48pm UTC](https://discuss.circleci.com/t/setting-a-job-parameter-default-to-another-parameter-fails-silently/45035 "2022-08-11T17:48:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcom000](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jcom000/32/30818_2.png) [@jcom000](https://discuss.circleci.com/u/jcom000)\
**Post date:** [August 11, 2022, 5:48pm UTC](https://discuss.circleci.com/t/setting-a-job-parameter-default-to-another-parameter-fails-silently/45035/1 "2022-08-11T17:48:31Z")

</div>

```auto
jobs:
  my-job:
    parameters:
      first-param:
        type: string
      second-param:
        type: string
        default: << parameters.first-param >>

```

expectation:  
i would expect the second-param to take on the value of the first-param if not specified.  
alternatively, i could expect a syntax error.

actual:  
instead, neither of these things happen, and the syntax fails silently.

---

<div class="post-metadata">

**Author:** ![ADes](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ades/32/33489_2.png) [@ADes](https://discuss.circleci.com/u/ADes)\
**Post date:** [August 2, 2023, 1:37pm UTC](https://discuss.circleci.com/t/setting-a-job-parameter-default-to-another-parameter-fails-silently/45035/2 "2023-08-02T13:37:41Z")

</div>

A work-around we found is to use bash to substitute empty parameter with a mandatory one.  
Our context is a command, but there is no reason for it not to work with jobs

```auto
commands:
    my-cmd:
        parameters:
            foo: # always set
                type: string
            bar: # Optional, takes foo as default
                type: string
                default: ''
            steps:
            - run:
                name: lint
                command: |
                    # substitute by foo only if bar is empty
                    bar_or_foo=`[-n "<< parameters.bar >>"] && echo "<< parameters.bar >>" || echo "<< parameters.foo >>"`
                    whatever $bar_or_foo

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [August 9, 2023, 1:37pm UTC](https://discuss.circleci.com/t/setting-a-job-parameter-default-to-another-parameter-fails-silently/45035/3 "2023-08-09T13:37:44Z")

</div>

Closed on August 9, 2023, 1:37pm UTC

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