Skip to main content

Pipelines

Semaphore supports simple pipelines with using build and deploy tasks.

Semaphore passes semaphore_vars variable to each Ansible playbook which it runs.

You can use it in your Ansible tasks to get what type of task was run, which version should be build or deployed, who ran the task, etc.


Example of semaphore_vars for build tasks:

semaphore_vars:
task_details:
type: build
username: user123
message: New version of some feature
target_version: 1.5.33

Example of semaphore_vars for deploy tasks:

semaphore_vars:
task_details:
type: deploy
username: user123
message: Deploy new feature to servers
incoming_version: 1.5.33

For Bash, PowerShell, and Python templates, Semaphore provides the same task_details values as environment variables:

task_details fieldEnvironment variableNotes
typeSEMAPHORE_TASK_DETAILS_TYPEbuild or deploy
usernameSEMAPHORE_TASK_DETAILS_USERNAMEUser who started the task
messageSEMAPHORE_TASK_DETAILS_MESSAGETask message
target_versionSEMAPHORE_TASK_DETAILS_TARGET_VERSIONPresent for build tasks
incoming_versionSEMAPHORE_TASK_DETAILS_INCOMING_VERSIONPresent for deploy tasks

Example for Bash:

echo "$SEMAPHORE_TASK_DETAILS_TYPE"
echo "$SEMAPHORE_TASK_DETAILS_TARGET_VERSION"

Example for PowerShell:

$env:SEMAPHORE_TASK_DETAILS_TYPE
$env:SEMAPHORE_TASK_DETAILS_INCOMING_VERSION

Example for Python:

import os

task_type = os.getenv("SEMAPHORE_TASK_DETAILS_TYPE")
target_version = os.getenv("SEMAPHORE_TASK_DETAILS_TARGET_VERSION")
incoming_version = os.getenv("SEMAPHORE_TASK_DETAILS_INCOMING_VERSION")

Build

This type of task is used to create artifacts. Each build task has autogenerated version. You should use variable semaphore_vars.task_details.target_version in your Ansible playbook to get what version of the artifact should be created. After the artifact is created, it can be used for deployment.


Example of build Ansible role:

  1. Get app source code from GitHub
  2. Compile source code
  3. Pack created binary to a tarball with name app-{{semaphore_vars.task_details.target_version}}.tar.gz
  4. Send app-{{semaphore_vars.task_details.target_version}}.tar.gz to an S3 bucket

Deploy

This type of task is used to deploy artifacts to destination servers. Each deployment task is associated with the build task. You should use variable semaphore_vars.task_details.incoming_version in your Ansible playbook to get what version of the artifact should be deployed.


Example of deploy Ansible role:

  1. Download app-{{semaphore_vars.task_details.incoming_version}}.tar.gz from an S3 bucket to destination servers
  2. Unpack app-{{semaphore_vars.task_details.incoming_version}}.tar.gz to destination directory
  3. Create or update configuration files
  4. Restart app service