Installing private python packages in the build plan
Asked by Piotr Wilk-Juraszek:

Hello,

I am trying to create a python virtual environment and install private packages with SSH protocol from **requirements.txt** file. Its content looks like this:

```
package1 @ git+ssh://git@bitbucket.org:USER/package1.git
package2 @ git+ssh://git@bitbucket.org:USER/package2.git
```

In the build stage I am using script task with powershell and executing command:

```
python -m pip install -r .\requirements.txt
```

This is the log that bamboo is generating:

```
simple 24-Jul-2024 10:40:13 Starting task 'Get dependencies' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script' 
command 24-Jul-2024 10:40:13 Beginning to execute external process for build 'TEST - test_plan - Default Job #32 (TEST-TEST-JOB1-32)'\n ... running command line: \nC:\bamboo_agent\temp\TEST-TEST-JOB1-32-ScriptBuildTask-8492469421397391151.ps1\n ... in: C:\bamboo_agent\xml-data\build-dir\TEST-TEST-JOB1\n 
build 24-Jul-2024 10:40:19 pip 24.1.2 from C:\bamboo_agent\xml-data\build-dir\TEST-TEST-JOB1\.venv\Lib\site-packages\pip (python 3.12) 
build 24-Jul-2024 10:40:20 Collecting git+ssh://git@bitbucket.org:USER/package1.git (from -r .\requirements.txt (line 3)) 
build 24-Jul-2024 10:40:20 Cloning git+ssh://git@bitbucket.org:USER/package1.git (to revision develop) to c:\windows\temp\pip-req-build-3z8q8j72 
error 24-Jul-2024 10:40:20 Running command git clone --filter=blob:none --quiet 'ssh://git@bitbucket.org:USER/package1.git' 'C:\Windows\Temp\pip-req-build-3z8q8j72' 
error 24-Jul-2024 10:40:21 Host key verification failed. 
error 24-Jul-2024 10:40:21 fatal: Could not read from remote repository. 
error 24-Jul-2024 10:40:21 
error 24-Jul-2024 10:40:21 Please make sure you have the correct access rights 
error 24-Jul-2024 10:40:21 and the repository exists. 
error 24-Jul-2024 10:40:21 error: subprocess-exited-with-error 
error 24-Jul-2024 10:40:21 
error 24-Jul-2024 10:40:21 git clone --filter=blob:none --quiet 'ssh://git@bitbucket.org:USER/package1.git' 'C:\Windows\Temp\pip-req-build-3z8q8j72' did not run successfully. 
error 24-Jul-2024 10:40:21 exit code: 128 
error 24-Jul-2024 10:40:21 
error 24-Jul-2024 10:40:21 See above for output. 
error 24-Jul-2024 10:40:21 
error 24-Jul-2024 10:40:21 note: This error originates from a subprocess, and is likely not a problem with pip. 
error 24-Jul-2024 10:40:21 error: subprocess-exited-with-error 
error 24-Jul-2024 10:40:21 
error 24-Jul-2024 10:40:21 git clone --filter=blob:none --quiet 'ssh://git@bitbucket.org:USER/package1.git' 'C:\Windows\Temp\pip-req-build-3z8q8j72' did not run successfully. 
error 24-Jul-2024 10:40:21 exit code: 128 
error 24-Jul-2024 10:40:21 
error 24-Jul-2024 10:40:21 See above for output. 
error 24-Jul-2024 10:40:21 
error 24-Jul-2024 10:40:21 note: This error originates from a subprocess, and is likely not a problem with pip. 
build 24-Jul-2024 10:40:21 
build 24-Jul-2024 10:40:21 
simple 24-Jul-2024 10:40:21 Finished task 'Get dependencies' with result: Success
```

My question is; How can I configure bamboo to use specific SSH key to execute this task correctly?


Answers:
author: Shashank Kumar
body: Hello Piotr,

Welcome to Atlassian community.

You can see an example at [How to perform a Git SSH checkout from a Bamboo Script Task](https://confluence.atlassian.com/bamkb/how-to-perform-a-git-ssh-checkout-from-a-bamboo-script-task-741999875.html) where there is a similar scenarion of what you are trying to achieve.

Let me know if this helps.

Regards,

Shashank kumar

**\*\*please don't forget to Accept the answer if your query was answered\*\***

comments: author: Piotr Wilk-Juraszek
body: Hello.

Thank you for your answer. I have seen this solution, but it seems to not work with something that I am trying to achieve.

I have tried something like this but it is not working:

    GIT_SSH_COMMAND='ssh -i /Path/to/file -o IdentitiesOnly=yes' python -m pip install -r .\requirements.txt

I need those repos to be installed in venv by **pip** in order to execute code that needs them. Pip is using **git** to clone repository, and then it is installing it to venv.

Key specified in `/Path/to/file` is added to bitbucket repositories.


Tags: python

ssh