Creating and automating Concourse CI pipelines

Photo by Simon Fitall on Unsplash

How do we set pipelines in Concourse CI?

fly -t ci set-pipeline -p booklit -c pipeline.yml

Automating your pipelines

Creating a self-sustaining pipeline

Concourse representation of the pipeline fleetmanager.yml
---
resources:
- name: councourse-ci
type: git
icon: gitlab
source:
uri: https://gitlab.com/user/concourse-ci.git
jobs:
- name: set-self
public: true
plan:
- get: councourse-ci
trigger: true
- task: init
config:
platform: linux
image_resource:
type: registry-image
source: {repository: ubuntu}
inputs:
- name: councourse-ci
run:
path: /bin/sh
args:
- -cx
- |
cd councourse-ci/
chmod +x setup_pipelines.sh
./setup_pipelines.sh set-fleetmanager
- name: configure-pipelines
public: true
plan:
- get: councourse-ci
trigger: true
passed: [set-self]
- task: init
config:
platform: linux
image_resource:
type: registry-image
source: {repository: ubuntu}
inputs:
- name: councourse-ci
run:
path: /bin/sh
args:
- -cx
- |
cd councourse-ci/
chmod +x setup_pipelines.sh
./setup_pipelines.sh set-fleet

Centralize your pipline configuration files

concourse-ci
- fleetmanager.yml
- setup_pipelines.sh
- CI
- backend.yml
- frontend.yml
- deployment.yml
- build.yml
- vars
- vars.yml
  • set-fleetmanager (creates/updates the self-sustaining managing pipeline)
  • set-fleet (creates/updates the pipeline(s) located in the CI directory)
#!/bin/bash
# Description: CI setup script
# Author: TroublingFox125
# Version 1.0
PROGRAM="fly"
PROGRAM_URL="https://github.com/concourse/concourse/releases/download/v7.0.0/fly-7.0.0-linux-amd64.tgz"
CONCOURSE_HOST="https://ci.example.com"
USER="user"
PASSWORD="pass"
RED='\033[0;31m'
NC='\033[0m' # No Color
BLINK='\e[5m'
echo "Initializing program"check_enviroment () {
echo "- Checking permissions"
if [ "$EUID" -ne 0 ]; then
printf "${RED}Please run as Administrator${NC}\n";
exit 1
fi
}check_program () {
./$PROGRAM &> /dev/null
if [ "$?" = "0" ];
then
echo " -> $PROGRAM" found
else
echo " -> $PROGRAM" not found. Downloading...
curl -L -O -J $PROGRAM_URL &> /dev/null
tar -xzvf fly-7.0.0-linux-amd64.tgz &> /dev/null
if [ "$?" = "0" ];
then echo " -> $PROGRAM" installed successfully.
fi
fi
check_success $? &> /dev/null
}
check_curl() {
which curl &> /dev/null
if [ "$?" != "0" ];
then
apt-get update
apt-get -y install curl
fi
}
check_dependencies (){
echo "- Checking dependencies"
check_curl &> /dev/null
check_program
}
concourse_login () {
echo "- Authenticating with $CONCOURSE_HOST"
./fly --target main login --concourse-url $CONCOURSE_HOST -u $USER -p $PASSWORD &> /dev/null
echo "- Syncing CLI version"
./fly -t main sync &> /dev/null
}
set_pipelines () {
echo "- Setting up pipeline(s)"
FILES=$(pwd)/CI/*.yml
dir="$(pwd)/CI"
for f in $FILES
do
set_pipeline $f $dir
done
}
set_pipeline_maintainer () {
echo "- Setting up pipeline(s)"
f="fleetmanager.yml"
dir="$(pwd)"
set_pipeline $f $dir
}
set_pipeline () {
echo " -> Processing $1 pipeline..."
filename=$(basename -- "$1")
filename="${filename%.*}"
./fly -t main set-pipeline --pipeline $filename --config $1 --load-vars-from $(pwd)/CI/vars/vars.yml -n &> /dev/null
check_success $? &> /dev/null
./fly -t main unpause-pipeline -p $filename &> /dev/null
check_success $?
}
check_success () {
if [ "$1" = "0" ];
then
echo " -> Done"
else
echo "ERROR: Check configuration of $f"
exit 1
fi
}
check_enviroment
check_dependencies
concourse_login
case "$1" in
#State
set-fleetmanager)
set_pipeline_maintainer ;;
#Options
set-fleet)
set_pipelines ;;
*)
echo "unknown option"
;;
esac
printf "${BLINK}End of program\n"
sudo ./setup_pipelines.sh set-fleetmanager

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store