简介
Gitlab Runner在Windows上运行之后,我们在.gitlab-ci.yml中编写script语句,思路和Linux是一样。但是考虑到Windows的特点,为了让程序员少接触一些知识点,以及给未来执行作业的时候预留更多的操作空间。简单说就是未来修改执行作业时候的逻辑,但是每个软件仓库根目录下的.gitlab-ci.yml不需要改动,我们一共编写了6个PowerShell脚本,和1个适配Directory.Build.props技术的windows批处理文件。
发布网站
function Build-Web {
param (
[string]$msbuild_dir,
[string]$ci_project_dir,
[string]$project_path,
[string]$web_output_path
)
$project_file = $ci_project_dir + "\\" + $project_path
if(( $project_path -like "/*") -or ($project_path -like "\\*")){
$project_file = $ci_project_dir + $project_path
}
echo "项目文件"$project_file
echo "版本号"$version
echo "网站输出路径"$web_output_path
cd $ci_project_dir
COPY-ITEM -PATH 'x:/gitlab-runner/scripts/download.bat' -Destination .
.\download.bat
if ($LASTEXITCODE -ne 0) {
throw "下载Directory.Build.props及其相关文件时出错。"
}
dotnet nuget locals http-cache -c
$exePath = $msbuild_dir + "\\msbuild.exe"
if(Test-Path -Path $exePath){
}
else
{
throw "MSBuild.exe directory not found:" + $msbuild_dir
}
cd $msbuild_dir
.\msbuild -restore $project_file /v:m
if ($LASTEXITCODE -ne 0) {
throw "还原项目时出错:" + $project_file
}
cd X:\gitlab-runner\tools\binding-redirect-helper
.\BindingRedirect check --project:$project_file --save:true
if ($LASTEXITCODE -ne 0) {
throw "自动更新web.config中的绑定重定向时时出错:" + $project_file
}
cd $msbuild_dir
.\msbuild $project_file /t:ResolveReferences /t:Compile /p:configuration="Release" /p:ReferencePath=X:\study\ErpFiles /t:_CopyWebApplication /p:WebProjectOutputDir=$web_output_path /p:OutputPath=$web_output_path"\bin" /v:m
Exit $LASTEXITCODE
}
黑夜里不停折腾的代码行者。