001 CI.sh 1.85 KB
Newer Older
据说甜蜜呢 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/bin/bash

set -e

# Import external functions
chmod +x ./devops/PipeLines/functions.sh
./devops/PipeLines/functions.sh

GetAppName appName
echo "Continuous integration for ${appName} starting..."

declare solutionName=($(grep -oP '(?<=SolutionName>)[^<]+' "devops/app.props"))
dotnet build ${solutionName}	 

echo "Please check the version of each microservice carefully !!!"
declare major=($(grep -oP '(?<=VersionMajor>)[^<]+' "build/version.props"))
declare minor=($(grep -oP '(?<=VersionMinor>)[^<]+' "build/version.props"))
declare patch=($(grep -oP '(?<=VersionPatch>)[^<]+' "build/version.props"))
declare version=${major}.${minor}.${patch}

declare registryUserName=($(grep -oP '(?<=ImageUserName>)[^<]+' "build/deploy.props"))

declare publishOutputDir=./publish

rm -fr ${publishOutputDir}
mkdir -p ${publishOutputDir}

function CI()
{
	declare publishable=$1
	declare imagename=$2

	echo ""
	declare imagefullname=${RegistryHost}/${registryUserName}/${imagename}:${version}
	declare publishFile=$3

	echo "begin delivery of master branch for ${imagename}..."
	mkdir -p ${publishOutputDir}/${imagename}
	dotnet publish ${publishFile} -o ../../publish/${imagename} -c release --no-restore  
	docker build -t ${imagefullname} ${publishOutputDir}/${imagename}
	docker push ${imagefullname}
	rm -fr ${publishOutputDir}/${imagename}
	echo "delivery of master branch for ${imagename}:${version} has been successful."
}

declare services=$(ls -l src/services | awk 'NR>1')
declare servicePrefix=""
declare serviceName=""
for service in ${services}
do
	servicePrefix=($(echo ${service} | awk '{print $9}')) 
	isPublishable=($(grep -oP "(?<=${servicePrefix}Publishable>)[^<]+" "/tmp/cicd.props"))
	GetServiceName "${servicePrefix}" serviceName
	CI "${servicePrefix}" "./src/${servicePrefix}/${serviceName}.csproj"
done

echo ""
echo "Continuous integration for ${appName} has been successful."