Adding a variable before merging pull request
Asked by Jan Pozivil:

Is it possible to add a custom dropdown with predefined values to the screen just before merging a pull request, so I can then access the value selected by user from within the pipeline launched by the merge?

I want be able to tell the pipeline, if the merge is \`major \| minor \| patch \| prerelease \| alpha\` type and then adjust the new version of the package accordingly using \`yarn version --\<value\>\`.


Answers:
author: Theodora Boudale
body: Hi Jan,

I'm afraid that this is not possible, only custom pipelines (that are triggered manually by a user) accept run-time variables. For this type of pipeline, the variables can be set by the user when the user triggers it:

* <https://support.atlassian.com/bitbucket-cloud/docs/pipeline-start-conditions/#Custom--manual--pipeline-variables>

If you don't mind triggering the pipeline manually, you could use a custom pipeline with a variable that you can set when you trigger the build.

Otherwise, the only other way I can think of is by changing the bitbucket-pipelines.yml file in the source branch and adjusting the version, before you merge a pull request.

Kind regards,  
Theodora

comments: author: Jan Pozivil
body: Hi Theodora, when you say _trigger manually_ -- how do I trigger a pipeline manually? Is that not the same as creating a pull request and then clicking merge?


author: Theodora Boudale
body: Hi Jan,

There are several ways to trigger a custom pipeline manually:

**1)** On Bitbucket Cloud website, go to the **Pipelines** page of the repo. On this page, where all the pipelines builds are listed, you will see an option **Run pipeline** at the top of the page (next to the **Schedules** option):

![Screenshot 2023-02-10 at 11.22.04.png](https://community.atlassian.com/t5/image/serverpage/image-id/239485i8C475F8E3373EA7F/image-size/large?v=v2&px=999 "Screenshot 2023-02-10 at 11.22.04.png")

If you select the **Run pipeline** option you will see the following dialog where you can select a branch and one of the pipelines available for this branch. If you select a custom pipeline with variables, you'll be able to select a value for the variables:

![Screenshot 2023-02-10 at 11.06.35.png](https://community.atlassian.com/t5/image/serverpage/image-id/239487iBD934E803BC6C6FC/image-size/large?v=v2&px=999 "Screenshot 2023-02-10 at 11.06.35.png")

<br />

**2)** If you go to the **Branches** page of the repo, and select the 3 dots under **Actions** for a branch, you will see the option **Run pipeline for a branch**:

![Screenshot 2023-02-10 at 11.06.53.png](https://community.atlassian.com/t5/image/serverpage/image-id/239488iDC9B9859A484F54B/image-size/large?v=v2&px=999 "Screenshot 2023-02-10 at 11.06.53.png")

**3)** If you open a commit (from the **Commits** page of the repo), on the right side of the page you will also see an option **Run pipeline**:

![Screenshot 2023-02-10 at 11.08.56.png](https://community.atlassian.com/t5/image/serverpage/image-id/239489iE3E4368D47410714/image-size/large?v=v2&px=999 "Screenshot 2023-02-10 at 11.08.56.png")

<br />

**4)** You can use our API to trigger a custom pipeline in a script on your local environment:

* <https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-post>

**5)** You can [create a schedule](https://confluence.atlassian.com/bitbucket/scheduled-builds-for-pipelines-933078702.html) to run a custom pipeline at hourly, daily, or weekly intervals. However, schedules don't provide the option to set a variable's value, so I don't think that would be a suitable option.  

<br />

> Is that not the same as creating a pull request and then clicking merge?

No, this is not the same. If you have in your bitbucket-pipelines.yml file a definition for

```
branches:
  main:
```

this pipeline will run automatically every time you push commits to the main branch or if you merge a PR to the main branch.

* <https://support.atlassian.com/bitbucket-cloud/docs/pipeline-start-conditions/#Branches>

Custom pipelines do not get triggered automatically when there are new commits to a branch, they need to get triggered with one of the ways I listed above.

If you have any other questions, please feel free to let me know.

Kind regards,  
Theodora


author: Jan Pozivil
body: Thank you, that sounds promising, especially the option 4 via API. Do I imagine it correctly that this could be triggered via some other task orchestration tool like [Jenkins](https://www.jenkins.io/)?


author: Theodora Boudale
body: You are very welcome Jan, and yes, this is also possible.


Tags: bitbucket-cloud

cloud