The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How Can I Get Triggered Pipeline Of Pull Request?

z
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

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

TAGS
AUG Leaders

Atlassian Community Events