# Is it possible to use Logic statements when setting parameters in jobs?

**URL:** <https://discuss.circleci.com/t/is-it-possible-to-use-logic-statements-when-setting-parameters-in-jobs/41862>\
**Category:** Build Environment\
**Created:** [November 9, 2021, 1:35pm UTC](https://discuss.circleci.com/t/is-it-possible-to-use-logic-statements-when-setting-parameters-in-jobs/41862 "2021-11-09T13:35:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robmosca-travelperk](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/robmosca-travelperk/32/28590_2.png) [@robmosca-travelperk](https://discuss.circleci.com/u/robmosca-travelperk)\
**Post date:** [November 9, 2021, 1:35pm UTC](https://discuss.circleci.com/t/is-it-possible-to-use-logic-statements-when-setting-parameters-in-jobs/41862/1 "2021-11-09T13:35:23Z")

</div>

Is it possible to use logic statements when setting a parameter in a step of a job definition? Like this:

```auto
parameters:
  pipeline-modified:
    type: boolean
    default: false
  extranet-portal-modified:
    type: boolean
    default: false

commands:
  tag_deployment_head_on_master:
    parameters:
      tag_name:
        description: Name of the tag
        type: string
      project_modified:
        description: A boolean parameter indicating if the project needs to be tagged
        type: boolean
    steps:
      ...

jobs:
  set_deployment_tags:
    steps:
      - checkout
      - tag_deployment_head_on_master:
          tag_name: head-extranet-portal-build
          project_modified:
            or: [<< pipeline.parameters.pipeline-modified >>, << pipeline.parameters.extranet-portal-modified >>]

```

The parameter `project_modified` is calculated as an `or` of two pipeline parameters of type `boolean`

---

<div class="post-metadata">

**Author:** ![nbialostosky](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/nbialostosky/32/24962_2.png) [@nbialostosky](https://discuss.circleci.com/u/nbialostosky)\
**Post date:** [November 9, 2021, 4:02pm UTC](https://discuss.circleci.com/t/is-it-possible-to-use-logic-statements-when-setting-parameters-in-jobs/41862/2 "2021-11-09T16:02:21Z")

</div>

Hi @robmosca-travelperk – great question!

We don’t have the ability to evaluate the logic statement with how you set up your example. Technically I think you could utilize some bash logic to work out the conditional logic there and just pass along the value. However, there is another approach with just using a step-level conditional logic and only executing the `tag_deployment_head_on_master` command if it’s `true`. Sample:

```auto
    steps:
      - checkout
      - when:
          condition:
            or:
              - equal: [true, << pipeline.parameters.pipeline-modified >>]
              - equal: [true, << pipeline.parameters.extranet-portal-modified >>]
          steps:
            - tag_deployment_head_on_master:
                tag_name: head-extranet-portal-build

```

Here is a full config example, if you execute the following in a job without modifying either of the pipeline parameters it will not execute the `tag_deployment_head_on_master` command:

```auto
version: 2.1

parameters:
  pipeline-modified:
    type: boolean
    default: false
  extranet-portal-modified:
    type: boolean
    default: false

commands:
  tag_deployment_head_on_master:
    parameters:
      tag_name:
        description: Name of the tag
        type: string
        default: ''
      project_modified:
        description: A boolean parameter indicating if the project needs to be tagged
        type: boolean
        default: false
    steps:
      - run: echo "hi"

jobs:
  set_deployment_tags:
    docker:
      - image: cimg/base:stable
    steps:
      - checkout
      - when:
          condition:
            or:
              - equal: [true, << pipeline.parameters.pipeline-modified >>]
              - equal: [true, << pipeline.parameters.extranet-portal-modified >>]
          steps:
            - tag_deployment_head_on_master:
                tag_name: head-extranet-portal-build

workflows:
  build-logic:
    jobs:
      - set_deployment_tags

```

However, if you trigger via the API and set the parameters or simply set one to `true` in the config, you’ll find the command is executed. Would the above work for you?

-Nick

---

<div class="post-metadata">

**Author:** ![robmosca-travelperk](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/robmosca-travelperk/32/28590_2.png) [@robmosca-travelperk](https://discuss.circleci.com/u/robmosca-travelperk)\
**Post date:** [November 12, 2021, 8:25am UTC](https://discuss.circleci.com/t/is-it-possible-to-use-logic-statements-when-setting-parameters-in-jobs/41862/3 "2021-11-12T08:25:53Z")

</div>

Thanks Nick, this is actually really useful. I think I will go for evaluating the boolean condition in the bash script, but the approach using the `when` clause is also good and something I didn’t think about.

Thanks!
