How to start a CI pipe in main after a merged PR?

I already have a CI pipe that runs on the feature branch when a PR is opened, reopened and synced.
Now that run the same pipe in main when PR is merged.
How do I configure a trigger for this?

Hello @dmarinss and welcome to the Codefresh community.

It depends on whether you want to run the pipeline on the branch where the pull request was opened, or the branch where the pull request was merged to.

Also if you are trying to replicate Trunk based development with Codefresh there is a full guide here Pull Requests and Branches · Codefresh | Docs

Hi Kotis. Thanks for the return.

I’m running github flow.

I want to run the CI on the target (main) branch, which the pull request was merged into.

I configured my trigger like this:

I tried using this step, but it didn’t work for me:

Actually, writing this, I think the trigger is already configured correctly, because when merging the PR, the pipe is started.

The real problem is getting the clone step to understand that it needs to checkout the feature branch first and then main when the PR is merged.

Hey @dmarinss

If you use CF_BRANCH as explained in Variables · Codefresh | Docs then it should work like you expect it.

Can you post your clone step here?

Hi Kotis. Apologies for the delay.

I managed to solve it using the “CF_REVISION” variable instead of the “CF_BRANCH” variable in the “Revision” property of the clone step.

I also removed the previous step that updated the “CF_BRANCH” variable.

So my step was like this:

     stage: setup
     title: 'Clonning repository'
     type: git-clone
     repo: '${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}'
     git: github
     revision: '${{CF_REVISION}}'

yarn_install: ...
lint: ...
unit_tests: ...
call_cd_pipeline: ...

With the “CF_BRANCH” variable, the checkout was performed by looking at the branch that had already been deleted (by policy) after the merge.

Great. I am glad that you found a solution!