Hi,
I know this has be discussed multiple times but I still can’t figure out how to reach my goal.
I’m implementing a CICD Pipeline in which I have an “Integrate and Testing” phase (with “Test” and “Clean up” steps) and a “Deployment” phase. I would like to kick the Integrate and Testing pipeline only when a developer makes a pull request and the Deployment phase only when a maintainer merge the code. I was able to achieve the first one adding this to the drone.yml file:
when:
event:
- pull_request
ref:
- refs/pull/**
but for the Deployment phase I’m still not able to isolate the merge push event and the problem that I’m facing is that the Deployment pipeline starts every time a mantainer push some changes to the codebase because GH is (correctly) generating a webhook event because it see a push to the master branch. I tried to use triggers and events with no luck.
Is there any way to “isolate” the merge push request in the drone.yml file?
Thank you!
hey there, if I’m understanding correctly you want to execute a pipeline on pull request and on merge to master. The below yaml would support this use case:
when:
ref:
- refs/pull/**
- refs/heads/master
Hi Brad,
thank you for your message. Not exactly … I have 2 pipelines and I would like to execute the first one (with 2 steps) on pull requests and the second one only when a mantainer merge the pull request. This is the YAML that I have so far:
name: Integrate and Test
kind: pipeline
type: docker
steps:
- name: Integrate-and-Test
image: ****
when:
event:
- pull_request
ref:
- refs/pull/**
- name: Cleanup-Test-Environment
image: ****
when:
status:
- success
- failure
event:
- pull_request
ref:
- refs/pull/**
---
name: deploy
kind: pipeline
type: docker
steps:
- name: deploy
when:
event:
- push
branch:
- main
ref:
include:
- refs/heads/master
with this YAML this is the behaviour that we see:
- When we push directly to the master only the deploy pipeline is executed while I would like to execute this only when a maintainer merge a pull request
- When a developer push to a branch an execution of both pipeline starts but not actions are taken and we just have the clone step. I would like to avoid this if possible.
- When we merge the code the second pipeline is correctly executed
Basically we would like to “improve” what we already have because to achieve the following:
- No pipeline execution when we push code directly to the master branch
- Deploy pipeline only on merge pull requests
Thank you for your support
I have 2 pipelines and I would like to execute the first one (with 2 steps) on pull requests and the second one only when a mantainer merge the pull request
you can use the below yaml to achieve this. note that we use the trigger
clause to limit when a pipeline is triggered, as opposed to enforce this at the individual step level with the when
clause.
name: Integrate and Test
kind: pipeline
type: docker
steps: ...
trigger:
event:
- pull_request
---
name: deploy
kind: pipeline
type: docker
steps: ...
trigger:
event:
- push
branch:
- master
Hi Brad,
Thank you for that. Your solution still execute the deploy pipeline when we push the code directly to the main branch while we would like to execute it only when we merge the code from a pull request.
Any other idea/suggestion?
Thank you
Your solution still execute the deploy pipeline when we push the code directly to the main branch while we would like to execute it only when we merge the code from a pull request.
github sends a push event when you push code to master, and github sends a push event when you merge a pull request to master. Because the event type is the same for pushes and merges, there is no way for Drone to differentiate between the two. So unfortunately there is no way to support your described use case.
Thank you Brad. That’s what I noticed looking at the Repository Webhook Settings on github and indeed there’s no option for the merge action…so there’s no way to implement this.
Thank you for the confirmation!