文章目录
前言
华为云流水线发布:自动检查代码,打包发布到服务器
一、新建代码检查
检查代码是否存在报错

设置规则集

二、新建编译构建

三、新建部署


模板选择空模板或者自己去创建自定义模板

bash
$directory = "${ProjectFile}"; if (-not (Test-Path -Path $directory)) { New-Item -Path $directory -ItemType Directory }
bash
$siteName = "dev" # 替换成你的网站名称
$site = Get-Website -Name $siteName
if ($site.State -eq "Started") {
C:\Windows\System32\inetsrv\appcmd.exe stop apppool /apppool.name:$siteName;
Stop-Website -Name $siteName;
Write-Host "The website $siteName has been stopped";
} else {
Write-Host "The website $siteName is in an unknown state"
}

bash
#上面截图:同时发布的两个站点,所以和下面的代码是不一样的,下面的去掉了一个站点
# 定义源文件路径和目标文件夹路径
$sourceFilePath = "${ProjectFile}/"
$destinationFolderPath = "D:/work/WebBackUp/service/${Project}/"
# 获取当前时间戳
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
# 构建目标文件路径
$destinationFilePath = Join-Path -Path $destinationFolderPath -ChildPath "file_$timestamp"
# 确保目标文件夹存在
if (-not (Test-Path -Path $destinationFolderPath)) {
New-Item -ItemType Directory -Path $destinationFolderPath
}
# 删除目标文件夹中的所有文件和子文件夹
Remove-Item -Path (Join-Path -Path $destinationFolderPath -ChildPath "*") -Recurse -Force
# 复制 $sourceFilePath 文件
Copy-Item -Path $sourceFilePath -Destination $destinationFilePath -Recurse -Force
删除文件根据自己需要添加,不再一 一截图了
bash
#上面截图:同时发布的两个站点,所以和下面的代码是不一样的,下面的去掉了一个站点
Copy-Item -Path D:/AppPackage/${Project}/${Time}/_PublishedWebsites/Web/* -Destination ${ProjectFile} -Recurse -Force

bash
#上面截图:同时发布的两个站点,所以和下面的代码是不一样的,下面的去掉了一个站点
$siteName = "dev" # 替换成你的网站名称
$site = Get-Website -Name $siteName
if ($site.State -eq "Stopped") {
C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:$siteName;
Start-Website -Name $siteName;
Write-Host "The website $siteName is running";
} else {
Write-Host "The website $siteName is in an unknown state"
}
三、新建流水线
模板选择空模板
