Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How Can I Get Triggered Pipeline Of Pull Request?

z April 26, 2022

I am using the Bitbucket API to access a pull request via its ID

```

https://api.bitbucket.org/2.0/repositories/${CONSTANTS.BITBUCKET_REPO_OWNER}/${REPO_NAME}/pullrequests/${PR_ID}

```

When a PR is merged from my "dev" branch to my "stage" branch, a pipeline is automatically triggered.

I want to know how I can get the pipeline ID of that merge. It seems that the pipeline API does not return what triggered it.

1 answer

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 29, 2022

Hi @z and welcome to the community.

Pull-requests pipelines run when a PR is created or updated.

If your pipeline runs automatically when a PR is merged, then the trigger is different.
It could be either the default pipeline, or a branches pipeline for the "stage" branch.

The pipelines API has a target object for each pipeline. If the trigger was a branch pipeline, this object looks as follows:

"target": {
"type": "pipeline_ref_target",
"ref_type": "branch",
"ref_name": "develop",
"selector": {
"type": "branches",
"pattern": "develop"
},
"commit": {
"type": "commit",
"hash": "0b0be990348b6b6f433216d7c2a68b1578aa42f9",
"links": { [...]
}
}
}

If the PR is merged via a merge commit, you can get the hash of the merge commit and then query pipelines builds for that commit.
Pipelines API does not support filtering at the moment, so you could use another tool, like jq, to filter the results.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events