How to run jar files from another bitbucket repo in main bitbucket pipelines?

Hareem Bokhari July 8, 2022

Hello,

I am working from my company's bitbucket account so I am trying to download the repo on which the required jar files are stored (I want to do this via ssh keys). I am working on creating the yaml file for bitbucket pipelines (for the main project repo) and I could not find a way to incorporate these jar files into my main repo as well as install dependencies - java 1.8 and sbt 1.6.2. I've seen a way to download the repo using a shell script and use maven... but is that necessary as there is no maven needed for this project? Please let me know which approach is best supported by Bitbucket to download jar files from external repos into bitbucket pipelines.

1 answer

0 votes
Ben
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 20, 2022

Hey Hareem,

Welcome to the Bitbucket Cloud Community! :)

I believe the easiest and best way to execute files from another repository using SSH is to clone the external repository in pipelines and then execute the files once it has been cloned. 

To do this, you will need to follow these steps to give the main repository read access to the target repository:

  1. You will need to generate an SSH key from the main repository (The repository executing pipelines)
  2. Under Settings > Pipelines > SSH keys
  3. Once you have generated the key, copy it
  4. Click 'Copy public key'
  5. Add the key to the repository you're looking to clone
  6. In the target repository: Settings > General > Access keys paste the key here
  7. Add a clone command to the bitbucket-pipelines.yml on the main repository
    script:
       - git clone git@bitbucket.org:workspaceID/reposlug.git
  8. Once the repo has been cloned in pipelines, you can cd to the directory and then run files from here:
    - cd ./reposlug
    - java -jar script.jar

There is an article here that explains this in-depth with screenshots:
https://bitbucket.org/blog/cloning-another-bitbucket-repository-in-bitbucket-pipelines 

Hope this helps.

Cheers!

- Ben (Bitbucket Cloud Support)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events