I have below config.yml code which is working fine, but the problem is by default build is getting triggered on every git push event so if I am pushing the code on any branch the build would be triggered, and the matter of fact is I want the build trigger when I push code to only particular develop branch.
Giving more details about my query
My project has 4 branches:
master
develop
develop-test
feature
release
Out of which only develop branch is circleci configured(contains .circleci/config.yml), other branches do not have circleci configuration, so right now according to my config.yml when I am pushing the change on release/feature/ develop-test/master the build is getting triggered and failing in couple of seconds as they don’t have config.yml file. So I want build triggered only if push event occurs to develop branch.
Once you’ve got the configuration fixed, I would recommend putting it (or a minimal version, with the filters) in your other branches to avoid pushes to those branches triggering a build.
I have already tried this solution, however again I tried below config.yml and pushed with my ‘develop’ branch, so that build has triggered automatically for ‘develop’ branch
Hi @prat3ik, could you confirm that the new config.yml file has been committed to your primary branch? By default this is master, however, this can be changed in the repository settings on GitHub, under “Branches”.
No, however I have tested with the sample project that is not happening either.
So for testing purpose I have created one simple project (having one test.txt file only). That project have 3 branches, and all of them(Except ‘test’ branch) contains same configuration shown below
Branches:
master (contains .circleci/config.yml)
develop (contains .circleci/config.yml)
test
.circleci/config.yml:
version: 2
jobs:
build:
filters:
branches:
only:
- develop
docker:
- image: circleci/node:4.8.2 # the primary container, where your job's commands are run
steps:
- checkout # check out the code in the project directory
- run: echo "hello world" # run the `echo` command
However when I push the code in test, it triggers the pipeline on circleci for test branch,
I just want to trigger pipeline if I do only push branch develop, for all other branches I do not want to trigger pipeline if I do push into them
No not really. We ended up keeping and adapting the tests in every branch.
Although the pipeline is always triggered, the configuration file is unique for each branch. So you can probably create some dummy successful tests for the branches you do not mind testing, and ignore them.
I had a similar issue that the filter to ignore “main” didn’t work. After consulting with a CircleCi engineer, she pointed out the spacing wasn’t correct
so, check the spaces and I hope they have a tool or at least a manual method to check the spaces. Here’s an example with the correct spaces:
check the spaces and see an example I provided below. You can specify in the filter whether to use (ignore) to ignore branches you specify below the filter from running or (only) to run the branches you specify below the filter. In my example above, I wanted to run all branches created in the repo except the main branch. So, you will need to add that in every branch including the main branch so that it doesn’t run when you push code to it.
I have indeed tried this, except with only and listing the branches i wanted the tests to run on, but it was not successful. I might have done something wrong with the spaces as you said, however I do not need it right now.