Accessing the Pull Request URL within a workflow step

build-config
step
#1

As seen in the screenshot, Bitrise has the Pull Request URL within the build page, but it seems this can’t be accessed within a step as none of the available environment variables provide this URL.

Why is there no $BITRISE_PULL_REQUEST_URL environment variable that this is stored in, and can this please be added?

0 Likes

#2

Hi @jastley!

This variable exists, only with a slightly different name: $BITRISEIO_PULL_REQUEST_REPOSITORY_URL

You can see the list of default available variables here: https://devcenter.bitrise.io/builds/available-environment-variables/

Hope this helps!

0 Likes

#3

Hi @bitce,

That environment variable only half works though. If the Bitrise app is configured via SSH, then $BITRISEIO_PULL_REQUEST_REPOSITORY_URL returns the SSH git URL, not the HTTPS URL I was pointing out in the screenshot.

0 Likes

#4

I see, thanks for clarifying! I was also incorrect, $BITRISEIO_PULL_REQUEST_REPOSITORY_URL seems to expose a HTTPS URL, but not for the PR but directly for the repo :thinking:

You should be able to get the URL by attaching the $BITRISE_PULL_REQUEST variable (which exposes the ID) to the end of a line containing the standard URL, but that feels a bit like a workaround.

Thanks for submitting this request! :slight_smile:

0 Likes

#5

…but the workaround you suggested only works if the Bitrise app is configured via HTTPS and not by SSH?

If the Bitrise app was configured via SSH, $BITRISEIO_PULL_REQUEST_REPOSITORY_URL returns git@bitbucket.org:<org>/<repo>.git, and appending $BITRISE_PULL_REQUEST to the end of that still won’t give you a usable URL.

It makes no sense that the output environment variable (regardless of HTTPS/SSH configured project) doesn’t output the whole pull request URL, while the build page (below) has no issue working it out and displaying it as you would expect it to…?

.

0 Likes

#6

I didn’t mean to specifically suggest to append the ID to the variable, I meant that you could have a line like the following one:

https://bitbucket.org/organisation/repository/pull-request/$BITRISE_PULL_REQUEST

Would that work? Admittedly it requires even more configuration if you wanna use this for multiple repos/orgs.

I completely understand the question though, getting the PR URL is done by the website and is git service dependant, the CLI does not expose this at the moment unfortunately.

0 Likes

#7

Ah right sorry I misinterpreted.

It’s a decent workaround for myself, however as I now maintain the Microsoft Teams step I was hoping to update the step to provide a direct “Go to Pull Request” button in the Teams message for PR builds, and requiring the user to provide the pull request base URL as another input for it to work is pretty clunky and less than ideal :confused:

0 Likes