Use Environment Variables in Parameters



im trying to build a customized “only build PR branches”. This is my config so far

version: 2.1

           type: string
           default: ""
      - when:
          condition: << parameters.should_build >>
              - do the building here
      - unless:
          condition: << parameters.should_build >>
              - run: echo "skipping non PR feature branch"

    version: 2.1
            - build:
                should_build: "$CIRCLE_PULL_REQUEST"

It seems the variable $CIRCLE_PULL_REQUEST is not properly interpolated in the parameters and is always true. I guess its because the config is processed before the parameter injection happens? If i comment the should_build parameter in the workflow job section, it works as expected.

The usecase for is that we have multiple default branches and cant use the “Only Build PR” Switch in the Project settings.


Hi @digitalkaoz,

Please see our environment variables documentation here:

I don’t believe CIRCLE_PULL_REQUEST will work here in the way you’ve outlined, as it is not a boolean but a URL string.


. I guess its because the config is processed before the parameter injection happens?

You hit the nail on the head. That is exactly the issue here. Environment variables can be used but it depends on the context.

For instance, here they are used in our Slack orb.

The difference is they are executed within the container, not as a part of the config logic.


I guessed that. Any other Idea howto achieve this? Maybe a list of branches that will Bypass the “build PRs only”


In this case you may need to do the conditional inside the shell commands you pass to run because of what Kyle said – the env var won’t be interpolated until you get to the runtime, and all the when logic is performed at config processing time prior to the job running.


Yeah thats not something that is usable. Maybe you can extend this feature to include a list of branches that will always trigger workflows, and do the filtering inside the Workflow?! Also how to run a Workflow for a pull request is openend when no commit is happening on that branch after?