# Need help to prevent duplicate builds for pull\_request and push

**URL:** <https://travis-ci.community/t/need-help-to-prevent-duplicate-builds-for-pull-request-and-push/12065>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** conditions, config, travis-build\
**Created:** [September 8, 2021, 11:56am UTC](https://travis-ci.community/t/need-help-to-prevent-duplicate-builds-for-pull-request-and-push/12065 "2021-09-08T11:56:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![notrev](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/notrev/32/7080_2.png) [@notrev](https://travis-ci.community/u/notrev)\
**Post date:** [September 8, 2021, 11:56am UTC](https://travis-ci.community/t/need-help-to-prevent-duplicate-builds-for-pull-request-and-push/12065/1 "2021-09-08T11:56:41Z")

</div>

Hello!

I am facing a problem where every push triggers a build and every pull request update also triggers a build. With this, whenever a new push is made to a pull request, two build processes start: one for updating the pull request, and one for making a push. Both executing duplicate stages: build and test.

I am trying to get around that by using the `commit_message` conditional, but still can’t get it to work as I want.

What I want:

- if the commit message contains the word `#ci-test`, run stages: build and test.
- if a pull request is updated or created, run stages: build, test and deploy to dev.
- if a push is made to the `master` branch, run stages: build, test and deploy to prod.

My (simplified) `.travis.yml` file is:

```auto
group: vm
services:
  - docker

git:
  depth: false

env:
  global:
    - MYVAR="VARVALUE"

jobs:
  include:
    - stage: "build"
      if: type = pull_request OR commit_message =~ /#ci-test/
      script: build_docker_image.sh

    - stage: "tests"
      if: type = pull_request OR commit_message =~ /#ci-test/
      script: run_tests.sh

    - stage: "deploy to dev"
      if: type = pull_request
      script: do_the_deploy_to_dev_magic.sh

    - stage: "deploy to production"
      if: type = push AND branch = master
      script: do_the_deploy_to_prod_magic.sh

```

Before I added the `commit_message` condition, it was running the jobs as expected, but only for pull request updates and for push to `master` branch. Pushes to other branches didn’t trigger anything, as expected. After adding the `commit_message` condition, it started triggering the jobs for every push, in any branch, again.

Another doubt I have is: Does `commit_message` condition check run only for the latest commit message, or does it check every commit message of a branch/push ?

Can anyone help me to figure out what am I doing wrong?

Thanks in advance.
