#!/usr/local/bin/bash
mapfile -t files < deploy_files_to_update.txt
for file in $files; do
    # safeguard against inserting tagProperties multiple times
    if ! grep -q tagProperties $file; then
        echo "Inserting datadog tags for ${file}"
        # insert datadog tagProperties if datadog element is found, save backup of original file to <file>.old
        sed -i .old -e 's/<org.datadog.jenkins.plugins.datadog.DatadogJobProperty plugin="datadog@0.7.1">/<org.datadog.jenkins.plugins.datadog.DatadogJobProperty plugin="datadog@0.7.1">\
<tagProperties>deploy=${SERVICE_NAME}\
environment=${ENV}\
app=ows\
<\/tagProperties>/g' $file
    fi
done
