Deploy a folder from one repo to bitbucket cloud through pipeline
Asked by Raj:

I am publishing a website on Bitbucket Cloud.

I have followed the [documentation](https://support.atlassian.com/bitbucket-cloud/docs/publishing-a-website-on-bitbucket-cloud/) and am manually pushing the static files (html) to bitbucket.io and am able to see those pages.

Now instead of manually pushing the files, I want to automate it with bitbucket pipeline.

I have a separate repo where the pipeline generates the folder containing the static html files. I want to push this folder into the bitbucket.io repo as part of the pipeline step.

I tried to add git clone commands on the bitbucket-pipeline.yaml file and then copy from one repo to another but something or the other keeps failing.

Is there any documentation that can guide me how this can be done?


Answers:
author: Ben
body: Hi Raj,

You are able to push from one repository to another by making use of our [Repository Access Token (RAT)](https://support.atlassian.com/bitbucket-cloud/docs/repository-access-tokens/) feature to grant the necessary privilege scope over HTTPS.

Essentially, you would follow the steps below - where **RepoA** is your source repository and **RepoB** is the target repository where you wish to push the file/folder:

1. Navigate to **RepoB** and select **Repository Settings \> Access Tokens** then click the **Create Repository Access Token** button
2. Give the token a name and ensure that it has the **WRITE** level privilege scope ticked against the **Repositories** heading (as a minimum)
3. Click the **Create**button and ensure that you copy the token, clone command and the git config command from the resulting dialogue box (as you cannot access this again)
4. Now that the token is created, navigate to **RepoA** and select **Repository Settings \> Pipelines: Repository Variables** then add the token you copied earlier as a secured variable here so that it can be referenced in your build without exposing it in plaintext
5. Access your **bitbucket-pipelines.yml** configuration on **RepoA** and make use of the variable you configured before to clone the **RepoB** repository, copy the folder you wish to push into its clone folder and then commit the changes. An example of this is highlighted in the code below which I have tested and confirmed as a working solution:

   ```
   WritetoRepo:
   - step:
       name: "Write to another repo"
       script:
       - git clone https://x-token-auth:$ACCESSTOKEN@bitbucket.org/workspaceID/test.bitbucket.io.git
       - cp -R foldername test.bitbucket.io
       - cd test.bitbucket.io
       - git config user.email alphanumericstring@bots.bitbucket.org
       - git add -A
       - git commit -a -m "Committing folder"
       - git push?
   ```

**NOTE:** You can use the**bots.bitbucket.org** email address that was provided when generating the access token to reflect in the commit history that it was committed by a bot, or you can simply use your own email address if you would prefer for your user to show here instead

Please attempt the above and let me know how it goes - I intend on adapting this into our documentation to assist future users :)

Cheers!

- Ben (Bitbucket Cloud Support)

comments: author: Raj
body: Apologies for the late reply Ben.

The solution that you provided worked. Thank you.

It will be a good addition to your documentation because some users may have similar ask as in my case.


author: Ben
body: Hi @\[deleted\]

Awesome news! I have already created documentation since and included instructions for SSH as well:  
<https://confluence.atlassian.com/bbkb/push-to-another-repository-in-pipelines-1277624367.html>  

Thanks,

Ben


Tags: bitbucket-cloud

bitbucket-pipelines

cloud

repository