I have a step which I would like to only run either on direct push to develop, or a PR from a feature branch to develop… However if I want develop to build on push, I can not exclude push, but then there will be a build on any push on the feature branch as well as PR. Is there a way to get more granular with the trigger and when rules? Or do I need to copy the entire step?
not sure I follow … can you please provide a full example yaml that demonstrates the problem / question?
For example, I have the following step:
- name: Build Application Image
image: docker:dind
privileged: true
environment:
APP_NAME:
from_secret: APP_NAME
ECR_ENDPOINT:
from_secret: ECR_ENDPOINT
volumes:
- name: dockersock
path: /var/run
commands:
- sleep 10
- docker build -t $APP_NAME --tag $ECR_ENDPOINT/APP_NAME:{DRONE_COMMIT} --tag $ECR_ENDPOINT/$APP_NAME:latest .
when:
branch:
- develop
- feature/*
I want this step to happen either on a direct push to develop, or on a PR from feature/* > develop. As is, it will also run on a push to feature/*. If I limit it when a event: include: pull_request, then it will no longer build when I push directly to develop.
I want this step to happen either on a direct push to develop, or on a PR from feature/* > develop.
The branch is evaluated against the target branch in a pull request, not the source branch.
If I limit it when a event: include: pull_request, then it will no longer build when I push directly to develop.
you could use the ref field to determine whether or not to execute a pipeline. It does not perfectly match your desired logic (since the target pr branch is used) but it gets pretty close. It would execute a build for all pull requests, and all pushes to develop.
when:
ref:
- refs/pulls/**
- refs/heads/develop
or you could do something like this (below) which would execute a pipeline on all pull requests to the target branch develop, or all pushes to develop:
when:
event:
- push
- pull_request
branch:
- develop
Thanks that may work. One other issue I’m seeing is that I have a service in my build, so even the branches I have no steps for are still displaying as a running pipeline with a service and no steps… Like if I push to feature/* using above I would still see a pipeline executed and succeeded only with a checkout and a service start but no steps. And then when I create a PR I would see two checks as passing on the gihub pr instead of the one
in that case, you might want to use the trigger
section to control whether or not an entire pipeline should execute, as opposed to evaluating each individual step. https://docs.drone.io/pipeline/docker/syntax/trigger/
Perfect, thank you, this is great stuff. I was being eaten alive by circleci costs and they can’t even handle pr requests properly, with the unused resources on my staging kubernetes cluster, this is really awesome!
Here’s another bit of an odd one…
On PR to develop I want pipeline to execute. Along with push to master or develop, but on a PR from master -> develop I do not want it to run as I have no steps, but the empty build still shows in the history.
It sounds like a configuration issue related to using when
clauses instead of trigger
clauses, but would need to see a full copy of your yaml to better understand.
Basically only talking about trigger for this one…
If I have a trigger on both develop and master with an event for pull_request and push, how do I then exclude the pull request only from develop to master, since I want to include prs into develop?
I see now you can include more then one pipeline in the same .drone.yml file by seperating them with a ___ which allows for different builds with different triggers. I assumed you could only have one pipeline with one set of triggers, this could probably be made more clear in the docs:)
this capability is documented in the configuration section:
https://docs.drone.io/pipeline/configuration/
open to actionable suggestions to make this more clear.
Ah must have missed it because I went straight to kubernetes -> configure. Perhaps one of the examples in there displaying multiple would have helped, thanks:)