ssh-add, Gitlab CI/CD with alpine image

Problem

Trying to use the usual way of adding Gitlab’s key to the ssh agent, is not working in alpine image (but it works in debian/ubuntu), and you get the following error message:

 - ssh-add <(echo "$GITLABCICD_PRIVATE_KEY")
/bin/sh: syntax error: unexpected "("

Solution

Try to use the following instead:

  - echo "$GITLABCICD_PRIVATE_KEY" | ssh-add -

Bash script to add environment and date in Symfony appversion.yml file

Problem

You are using CI/CD to deploy a Symfony application that has the appversion.yml configuration file, and you want to add the environment and a timestamp to it after deployment.

Solution

You can achieve this by creating and running a bash script like the following and passing the environment as a variable (ie script_name env) :

#!/bin/bash
# Script for adding the environment and time in deployment
# Needs the environment as a parameter
# DATE_CREATED=2017.06.07
# DATE_UPDATED=2017.06.08
# VERSION=1.01

CONF_PATH=/var/www/analyse/app/config

sed '/app.version/s/\(.*$\)/\1'" (${1}) $(date +%Y%m%d-%H%M)"'/g' $CONF_PATH/appversion.yml > $CONF_PATH/appversion_new.yml
mv $CONF_PATH/appversion.yml $CONF_PATH/appversion_bak.yml
mv $CONF_PATH/appversion_new.yml $CONF_PATH/appversion.yml