im trying to build a customized “only build PR branches”. This is my config so far
version: 2.1
jobs:
build:
parameters:
should_build:
type: string
default: ""
steps:
- when:
condition: << parameters.should_build >>
steps:
- do the building here
- unless:
condition: << parameters.should_build >>
steps:
- run: echo "skipping non PR feature branch"
workflows:
version: 2.1
features:
jobs:
- 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.
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?
Can you or anyone at CircleCI please offer some advice on how we can get around this limitation? Is there any sort of API that we could use to try to manually trigger things or some experimental feature we may not know about? Our organization is large, and running many extra builds from users that haven’t opened PRs just so we can deploy to a few extra branches is not going to work for us. We were just about to migrate completely from Travis until we hit this limitation and have been at a standstill for a while now. Thanks for your help
@wesleykendall Great question! I don’t think it relates to this topic though?
I’m pretty sure we can help you find a solution—the branch/tag filters we provide for Workflows jobs are fairly robust and flexible.
Can you open a support ticket so we can help you out (feel free to manually CC the folks you tagged here, if you’d like)?
EDIT: oh, I see, it relates to the specific use case the OP was outlining. That said, the approach in that use case (using environment variables in parameters) will not get you where you’re trying to go here, so I still think it’s best to have this conversation elsewhere.
@speeddragon what specifically would you like a solution for? What are you trying to do? There are some workarounds here, depending on how you implement things.