echo "======solution dircectory======";
ls;
echo "======building version======";
$versionDate=Get-Date -Format ‘yyyyMMddHHmmss‘;
echo "v$versionDate";
echo "======begin restore packages======";
dotnet restore "Hoa.Web.Host/Hoa.Web.Host.csproj" -s "https://api.nuget.org/v3/index.json" -s "https://www.myget.org/F/miniprofiler/api/v3/index.json";
echo "======restore success======";
echo "======begin build code source======";
dotnet build "Hoa.Web.Host/Hoa.Web.Host.csproj" -c Release -o "H:/devops/hoawebapi/v$versionDate/build";
echo "======build success======";
echo "======begin publish code source======";
dotnet publish "Hoa.Web.Host/Hoa.Web.Host.csproj" -c Release -o "H:/devops/hoawebapi/v$versionDate/publish";
echo "======publish success======";
echo "======begin set asp.net core environment======";
set ASPNETCORE_ENVIRONMENT=Staging
echo "======set success======";
echo "======go to publish direcctory======";
pushd "H:/devops/hoawebapi/v$versionDate/publish";
echo "======view 5000 point======";
$points=(netstat -ano | findstr 5000);
echo $points;
if($points.gettype().Name -eq "Object[]"){
$points=$points.get(0);
}
echo "======kill 5000 point======";
$pids=-Split $points;
if($pids.length -gt 0) {
taskkill /t /f /im $pids[$pids.length-1];
echo "======kill success======";
}
echo "======create run bat file======";
$runscripts = "dotnet Hoa.Web.Host.dll --urls=http://*:8080";
$runscripts | Out-File "./run.bat";
echo "======begin run application======";
start ./run.bat
echo "======programe run success======";
Jenkins + PowerShell + .net core 自动打包