Jenkins + PowerShell + .net core 自动打包

注意,IIS路径一定要用 \ ,不能用 /

https://blog.csdn.net/aixian3620/article/details/102205138

echo "======solution dircectory======";
ls;

echo "======building version======";
$versionDate=Get-Date -Format 'yyyyMMddHHmmss';
echo "v$versionDate";

$iisSiteName="hoawebapis";
$sourceBuildPath="H:\devops\hoawebapi\v$versionDate\build";
$sourcePublishPath="H:\devops\hoawebapi\v$versionDate\publish";

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 $sourceBuildPath;
echo "======build success======";

echo "======begin publish code source======";
dotnet publish "Hoa.Web.Host/Hoa.Web.Host.csproj" -c Release -o $sourcePublishPath;
echo "======publish success======";

echo "======begin set asp.net core environment======";
[Environment]::SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Staging", "Machine")
echo "======set success======";

echo "======go to publish direcctory======";
pushd $sourcePublishPath;

echo "======change appsetting.json======";
Remove-Item ./appsettings.json -Recurse;
Rename-Item ./appsettings.Staging.json appsettings.json;
echo "======change success======";

pushd C:\WINDOWS\system32\inetsrv;

echo "======change iis dir======";
./appcmd set vdir "$iisSiteName/" -physicalPath:$sourcePublishPath;
echo "======change success======";

echo "======restart iis site======";
./appcmd stop site $iisSiteName;
./appcmd start site $iisSiteName;
echo "======restart success======";

echo "The Application is running......";
posted @ 2020-06-05 19:26  百小僧  阅读(440)  评论(0编辑  收藏  举报