I would like to use runners to run the test cases on pullrequest.
Asked by Win Yourself:

I would like to use runners to run the test cases on pullrequest, earlier i was using bitbuckets infrastructure to run the test cases whenever i do PR for the target branch.

The benifit for this approch was: **A special pipeline that only runs on pull requests initiated from within your repository. It merges the destination branch into your working branch before it runs. [Pull Request](https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/#:~:text=A%20special%20pipeline%20that%20only%20runs%20on%20pull%20requests%20initiated%20from%20within%20your%20repository.%20It%20merges%20the%20destination%20branch%20into%20your%20working%20branch%20before%20it%20runs)**

But as my test cases are started increasing , and was getting**Container "Build" failure** even using **2x as size**, so decided to use Runners feature to run my test cases on self hosted server.

**My question is.
- Can I use Runners to execute test cases whenever PR is raised.**

**- How can i get the benifit of "It merges the destination branch into your working branch before it runs"**

**Thanks**


Answers:
author: Norbert C
body: Hi [@Win Yourself](/t5/user/viewprofilepage/user-id/4426356) ,

Thank you for contacting Atlassian Community, I'm Norbert from Bitbucket Cloud Support Team, it's nice to meet with you!

I'd like to inform you what you would like to achieve is possible, you can do it the following way:

```
pipelines: 
   pull-requests: 
     '**': #this runs as default for any branch not elsewhere defined 
       - step:
          runs-on: 
            - self.hosted
          script:
           - 
           - 
```

Answering your other question "How can i get the benifit of "It merges the destination branch into your working branch before it runs"

I'd like to inform you that this is fully automatic, once the Pipelines is initiated from a PR, it gets merged automatically.

Please let me know if you have any further question? We're here to help.

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support

comments: author: Win Yourself
body: Actually I have started working on this litle experiment, really appreciate your response on my questions.

The docker command which we get while setting up the runner, that does the real trick.

Once again thanks [@Norbert C](/t5/user/viewprofilepage/user-id/1190200)


author: Norbert C
body: You're welcome [@Win Yourself](/t5/user/viewprofilepage/user-id/4426356) , I'm glad to hear I could help :)


author: Win Yourself
body: Hi [@Norbert C](/t5/user/viewprofilepage/user-id/1190200) ,

I was able to run the pipeline on my hosted machine, but following things I have noticed.

1. When the pipeline successfully get executed or when it gets failed. It removes the created container.

And because of this whatever resources I am downloading via script in pipeline, those are also getting removed

2. And when I run the same pipeline again, then whole process gets repeated, which leads to unnecessary time consumption.

Is there any way where we can persist downloaded data in a container, i don't want to download the data again and again.

Thanks Man


author: Norbert C
body: Hi [@Win Yourself](/t5/user/viewprofilepage/user-id/4426356)

I would like to inform you that actually this is working as expected.

Basically how Pipelines works is that when someone pushes a commit or creates a pull requests, Bitbucket Pipelines temporarily creates a container, where it's cloning the repository and runs the script from bitbucket-pipelines.yml file. When the build successfully executes or fails, the container is getting destroyed as there are no more things to do.

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support


author: Pritesh Tamhankar
body: Thanks for your response [@Norbert C](/t5/user/viewprofilepage/user-id/1190200)

Got it, it's also mentioned in the official doc. [Link](https://support.atlassian.com/bitbucket-cloud/docs/runners/#:~:text=Can%E2%80%99t%20access%20the%20local%20files%20on%20the%20runner%20host%20from%20a%20build%20script)  

In this doc it's also mentioned that we can use the [SCP / Rsync.](https://support.atlassian.com/bitbucket-cloud/docs/runners/#:~:text=we%20recommend%20using%20SCP%20/%20Rsync)

could you please tell me, how can i use this command in bitbucket-pipelines.yml file,  

where i can download/access/copy the resource from other server to running container, so whatever scripts i am calling from bitbucket-pipelines.yml they can use these resources.

Thanks Man


author: Norbert C
body: Hi [@Pritesh Tamhankar](/t5/user/viewprofilepage/user-id/4729062)

You're welcome.

What I would like to recommend you is:

\* Setup the SSH-keys between your host and Pipelines by following the steps here: <https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/>

\* Once you setup the SSH keys, you can copy the files from the host to the Pipelines build by doing this command:  

```
rsync -e "ssh -o StrictHostKeyChecking=no" -a username@ip.of.the.host:/<path.in.the.host> <directory in the container build>
```

Please let me know how it goes, I'm here to help :)

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support


author: Win Yourself
body: Hi [@Norbert C](/t5/user/viewprofilepage/user-id/1190200) ,

Apologies for the delay in the response.

I will work on this.

Thanks again.


author: Win Yourself
body: Hi [@Norbert C](/t5/user/viewprofilepage/user-id/1190200)

i have followed the documentation to setup ssh keys.  

However i think i have missed something not able to figure out, what it is

currently i am getting connection refused error.  
![e1.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/183733i0E9A3AB1595D5BCD/image-size/large?v=v2&px=999 "e1.PNG")

what i have done.. to test this.

- created new repo

- generated ssh keys

- updated the know host

- added the public key in authorized_keys (remote server)

-add on to this, also added the remote server ssh key to bitbucket acc ---\> personal settings --\> ssh key section.

- and yes my bitbucket pipeline.yml looks simple, through command arg i am trying to execute bash script available on remote server.![e2.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/183736iD83AC96986EA433E/image-size/large?v=v2&px=999 "e2.PNG")  

could you share your thoughts on this.

Thanks Man


author: Norbert C
body: Hi [@Win Yourself](/t5/user/viewprofilepage/user-id/4426356)

It seems that Pipelines is not capable to connect to your remote server.

Can you whitelist all the Bitbucket related IPs on your firewall and let us know if that fixes the issue? [What are the IP addresses to configure a corporate firewall?](https://support.atlassian.com/bitbucket-cloud/docs/what-are-the-bitbucket-cloud-ip-addresses-i-should-use-to-configure-my-corporate-firewall/)

Please let me know.

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support


author: Win Yourself
body: [@Norbert C](/t5/user/viewprofilepage/user-id/1190200)Thanks for the response.

This step makes sense.

All good, thanks again.

Regards


author: Norbert C
body: You're welcome [@Win Yourself](/t5/user/viewprofilepage/user-id/4426356) I'm glad to hear I was able to assist you.

Have a great weekend ahead!

Best Regards,  
Norbert  
Atlassian Bitbucket Cloud Support


Tags: bitbucket-runners

pull-request