api-preview-docs icon indicating copy to clipboard operation
api-preview-docs copied to clipboard

only 'master' branch is triggered using v2 API

Open Erilarn opened this issue 6 years ago • 6 comments
trafficstars

I'm trying to trigger a build on specified branch using such v2 API call:

curl -u ${CIRCLECI_TOKEN}: -X POST "Content-Type: application/json" -d '{"branch": "some-branch"}' https://circleci.com/api/v2/project/${project_slug}/pipeline

EXPECTED RESULT: I expect the branch specified in branch parameter will be triggered.

ACTUAL RESULT: Instead of specified branch master always trigger.

Erilarn avatar Aug 16 '19 10:08 Erilarn

This seems to be working pretty consistently for us. @Erilarn Can I check, does ${project_slug} in your example expand to :vcs/:org/:project as per the documentation? For example: https://circleci.com/api/v2/project/github/mycompany/myrepo/pipeline ?

peterbamsey avatar Aug 19 '19 10:08 peterbamsey

@peterbamsey As you can see from the actual result I'm able to trigger the build using my ${project_slug}. Doesn't it mean it's correct?

Erilarn avatar Aug 19 '19 14:08 Erilarn

+1

izikorgad avatar Aug 28 '19 15:08 izikorgad

Had the same problem, and found the issue. You have to add a header with content type application/json. The following should work for you: curl -u ${CIRCLECI_TOKEN}: -X POST "Content-Type: application/json" -H 'Content-Type: application/json' -d '{"branch": "some-branch"}' https://circleci.com/api/v2/project/${project_slug}/pipeline

ya-riel avatar Aug 28 '19 16:08 ya-riel

@ya-riel I checked it out. You're right, thank you so much!

Erilarn avatar Aug 29 '19 12:08 Erilarn

Glad to hear that I helped. Just for the record - the credit for pinpointing the issue goes to @izikorgad ;)

ya-riel avatar Sep 03 '19 18:09 ya-riel