Python with Bitbucket Pipelines
Here's how you can configure the bitbucket-pipelines.yml file to build and test a Python project.
Specify your Python version with Docker
Bitbucket Pipelines runs all your builds in Docker containers using an image that you specify at the beginning of your configuration file. You can easily use Python with Bitbucket Pipelines by using one of the official Python Docker images on Docker Hub. If you use the default Python image it will come with pip installed by default to help you manage your dependencies.
For instance, you can use Python 3.5.1 by specifying it at the beginning of your bitbucket-pipelines.yml file.
If you wanted to use a different version of Python you simply need to change the tag of the Python Docker image. The example below would start a container with Python 2.7.13
You can find a list of all supported Python versions and corresponding image tags, refer to https://hub.docker.com/r/library/python/.
Note that the Django Docker images have been deprecated in favor of the standard Python images mentioned above.
If you are using a requirements.txt file, you can simply run pip at the beginning of your script to install all the dependencies.
You can also install dependencies with the pip install command.
It is not yet possible to use multiple containers in a running pipeline, but you can use or create a Docker image that contains both Python and the required database. You will find below some examples of images that you can re-use or adapt to meet your requirements.
You simply need to add to your bitbucket-pipelines.yml file the same commands that you would run locally to test your application. Following are some examples for specific Python tools.
Running PyUnit tests is quite straight forward.
To test your Django projects, you can run it the same as you run Django tests locally. Just remember to make sure that Django is installed in your Pipelines environment too.
Was this helpful?
Thanks for your feedback!