Search
⌃K

CI Pipelines

A CI Pipeline simplifies deployments by automating the process of preparing, testing, and running your application. Just define the commands (steps) that need to be executed for each part. These steps will run when you start the pipeline, or when your workspace restarts.
The CI Pipeline is organized in three stages. Stages help to keep the deployment process organized by grouping related tasks.
  • Prepare - Install dependencies and build your code after updates.
  • Test - Run automated test steps after deployments.
  • Run - Run your application's server code. Restarts automatically if any crash occurs.

Prerequisites

  • A Codesphere account
  • A Codesphere workspace
You can set up a specific CI Pipeline for each workspace. Our templates come with a predefined CI Pipeline you can use or adjust to fit your needs.

Add a CI Pipeline config to your workspace

If you don't have a CI pipeline defined, clicking on CI Pipeline will open a panel with a Define CI Pipeline button in it. Clicking on it will open the configuration editor.

Edit your CI Pipeline

For each stage you can define multiple steps. We recommend providing meaningful names, especially when adding multiple steps per stage. The command can be anything you would otherwise run from a terminal.

Outsource longer scripts (optional)

If you have a lot of and/or longer commands you’d like to execute, you can also create scripts and have them executed from the CI Pipeline.
An example of this can be found in our WordPress template.
The Run stage there looks like this:
command: "./start.sh"
The start.sh script looks like this:
start.sh
1
#!/bin/bash
2
​
3
set +e
4
​
5
SCRIPT=$(realpath "$0")
6
SCRIPTPATH=$(dirname "$SCRIPT")
7
​
8
mkdir -p /tmp/log
9
mkdir -p /tmp/run
10
​
11
export PHPRC=$SCRIPTPATH/php
12
​
13
if [ ! -f "/tmp/run/php7.4-fpm.pid" ]; then
14
echo "Start PHP FPM Service"
15
php-fpm7.4 -y $SCRIPTPATH/php/php-fpm.conf
16
fi
17
​
18
echo "Start nginx on port 3000"
19
nginx -c $SCRIPTPATH/nginx.conf -g 'daemon off;'

Working with the CI Pipeline

Now that the setup is complete navigate to your CI Pipeline to see the steps.
You can select each stage and run it as needed. Whenever you’ve made bigger changes you will likely want to run the prepare stage and, if you defined automated tests, the test stage.
The run stage will start your application and, as long as it’s running, will make sure it stays on by restarting automatically on failures. To stop the application server, stop the run stage. Each stage displays its output on the right side of the CI Pipeline panel.

Sharing the Pipeline config across workspaces

If you intend to create multiple Codesphere workspaces from the same repository, e.g. for staging environments, it can be time saving to add the created ci.yml to your version control. To do this, simply open a terminal, commit and push the ci.yml file to your remote repository. This way, any newly created workspace will already have a configured CI Pipeline.
git add ci.yml
git commit -m 'Add Codesphere pipeline config'
git push