Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peteristhegreat/a47685e00513f4f94988c18f060dc62c to your computer and use it in GitHub Desktop.
Save peteristhegreat/a47685e00513f4f94988c18f060dc62c to your computer and use it in GitHub Desktop.
Make Build Configs easier to read from TeamCity, extract to sh files
#!/usr/bin/env bash
function pause(){
read -n 1 -r -s -p $'Press enter to continue...\n'
}
function usage()
{
cat << HEREDOC
Run from the root of the teamcity repo
HEREDOC
}
files=$(find .teamcity -name '*.xml' | ggrep -v "plugin-settings.xml" | ggrep -v "project-config.xml")
output_dir=copies_of_build_config_scripts
mkdir -p $output_dir
# set -x
for file in $files; do
echo $file
name=$(xpath -q -e '/build-type/name/text()' $file | sed -e 's: :@:g')
project_path=$(echo "$file" | sed -e 's:.teamcity/\(.*\)/buildTypes/\(.*\)\.xml:\1/\2:g')
project_path=$(dirname $project_path)/$name
# echo $project_path
# project_path=$(echo "$project_path" | gsed -e 's|^\(\w+?\_\w+?\)/\1+|\1/|g')
if [[ "$(basename $project_path)" == "$(dirname $project_path)"* ]]; then
project_path=$(basename "$project_path")
fi
# project_path=$(echo "$project_path" | gsed -E 's:(.*)_:\1/:')
project_path=$(echo "$project_path" | gsed -E 's:_:/:g')
project_path=$(echo "$project_path" | gsed -E 's:@:_:g')
# echo $project_path
sh_filename="$(basename $file)"
sh_filename="${sh_filename/.xml/.sh}"
runner_count=$(xpath -q -e 'count(/build-type/settings/build-runners/runner)' $file)
if [ "$runner_count" -ge 1 ]; then
# runner_count_minus_1=$(bc <<< "$runner_count - 1")
for count in $(seq 1 $runner_count); do
count_filename=${project_path}_${count}.sh
# count_filename="${sh_filename/.sh/_${count}.sh}"
echo $count_filename
mkdir -p "$output_dir/$(dirname $project_path)"
xpath -q -e '/build-type/settings/build-runners/runner['$count']/parameters/param[@name="script.content"]/text()' $file > $output_dir/$count_filename
done
else
echo "No runners found in $file"
fi
# pause
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment