Initialise Python with GoCD

Following the deployment of a python-aware agent, we can start creating a pipeline. The first stage would be to:

  1. Clean up any previous data
  2. Create a virtual environment for python
  3. Install all dependencies from a requirements.txt file in our project

Note: we assume the global pipeline settings and the Materials are properly set up (e.g. out project will be checked out in ./project).

Since the above operations must be executed in order, I’ve set up a Setup stage with a job named virtualenv. The job has three tasks:

  1. rm
  2. virtualenv
  3. pip install


This task is a generic shell command rm. We delete the venv/ directory created by previous runs, so we’ll use rm -rf venv

IMPORTANT: Make sure you don’t have trailing spaces in the Args input widget for the Task! Otherwise, the various flags will be quoted (e.g. "-rf ") and the execution will fail.


This task will create a virtual environment named venv. We still use a shell command to run virtualenv through python like /usr/bin/python -m virtualenv venv

pip install

We need to execute pip install in the current virtual environment. Since GoCD command type doesn’t execute multiple commands (which is arguably a feature), we need to run the command through python as well:

We’re executing the command in our checked out project directory. Therefore, our virtual environment python is located at ../venv/bin/python and the command line would be:

Now, the value of all tools (python, c compiler, crypto libraries) we installed in our python-aware agent comes to shine :)


The XMl generated by the above steps is:


A little experiment: If you find this post and ad below useful, please check the ad out :-)

One thought on “Initialise Python with GoCD

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top