How to run python script in virtualenv?

This is my (example) python script:

!#${bamboo.build.working.directory}/../${bamboo.planKey}/env/bin/python3 <<EOF
print("Hello World")
EOF

This is the error I am getting:

/opt/bamboo-home/temp/RTE-RT-HDR-14-ScriptBuildTask-7622273598056907388.sh: 1: /opt/bamboo-home/temp/RTE-RT-HDR-14-ScriptBuildTask-7622273598056907388.sh: !#/opt/bamboo-home/xml-data/build-dir/RTE-RT-HDR/../RTE-RT/env/bin/python3: not found

I have successfully created the virtualenv in a previous stage. Logging into the machine and executing:

/opt/bamboo-home/xml-data/build-dir/RTE-RT-HDR/../RTE-RT/env/bin/python3

starts python3.

It fails with both Interpreters "Shell" and "/bin/sh or cmd.exe".

2 answers

This widget could not be displayed.

Hi Tobias,

 

Since Bamboo only uses "Shell" and "/bin/sh or cmd.exe" I am suspecting running python commands using the script task won't be possible.

But, I have a workaround:

  1. Create your python script and store it at some location.
  2. In the Bamboo Script Task use the following command to invoke the python script:
    python <path-to-file>/filename.py

 

Also, ensure that you have the python in the path such as :

PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"

If you find this answer useful, please accept it so that others can also benefit from it.

 

Thanks,

Robhit

This widget could not be displayed.

I've done something similar to Rohit (see above). This is how my script looks now:

VIRTUALENV_DIR=/${bamboo.build.working.directory}/../${bamboo.planKey}/env

$VIRTUALENV_DIR/bin/python3 <path_to_script>/script.py

 

(a previous job has created the virtualenv in the plan directory)

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

124 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you