I want only build when pushes comes from master branch how can i do that

version: 2.1

orbs:

python: circleci/python@1.5.0

jobs:

build-and-test: # This is the name of the job, feel free to change it to better match what you’re trying to do!

docker:

  - image: cimg/python:3.8.0



steps:

  - checkout

  - python/install-packages:

       pkg-manager: poetry

  - run:

      name: Run tests

      command: python -m pytest

workflows:

sample: # This is the name of the workflow, feel free to change it to better match your workflow.

jobs:

  - build-and-test

You will need to read up on

  • using jobs - these allow you to combine the steps you have defined into a named unit of work
  • using workflows - these allow you to execute jobs based on rules set in filters.

The starting point in the docs regarding workflows and filters seems to be this

  https://support.circleci.com/hc/en-us/articles/115015953868-Filter-workflows-by-branch-

The following example which I have taken from another post may help a little

version: 2.1

workflows:
  version: 2
  build-and-test:
    jobs:
      - build-and-test:
          filters:
            branches:
              ignore:
                - gh-pages

jobs:
  build-and-test:
    docker:
      - image: circleci/node:12.14.0-browsers
    steps:
      - checkout
      - run: npm ci
      - run: npm test

As you can see the job is basically the script you have posted, but with an assigned name. The workflow then runs the job based on the defined filter.