简介
Gitlab Runner在Windows上运行之后,我们在.gitlab-ci.yml中编写script语句,思路和Linux是一样。但是考虑到Windows的特点,为了让程序员少接触一些知识点,以及给未来执行作业的时候预留更多的操作空间。简单说就是未来修改执行作业时候的逻辑,但是每个软件仓库根目录下的.gitlab-ci.yml不需要改动,我们一共编写了6个PowerShell脚本,和1个适配Directory.Build.props技术的windows批处理文件。
1、打包C#库项目
function Build-Project {
param (
[string]$msbuild_dir,
[string]$ci_project_dir,
[string]$project_path,
[string]$version,
[string]$output_path
)
$project_file = $ci_project_dir + "\\" + $project_path
if(( $project_path -like "/*") -or ($project_path -like "\\*")){
$project_file = $ci_project_dir + $project_path
}
if (-not $output_path) {
Write-Host "没有传入第5个参数,nupkg包将放在解决方案根目录的nupkg中"
$output_path =$ci_project_dir + "/nupkg"
} else {
Write-Host "指定了nupkg包的输出目录"
}
Write-Host "nupkg包的输出目录是:" + $output_path
echo "项目文件"$project_file
echo "版本号"$version
echo "输出路径"$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
if ($LASTEXITCODE -ne 0) {
throw "MSBuild.exe directory not found:" + $msbuild_dir
}
.\msbuild -restore $project_file /v:m /p:NuGetNoCache=true
if ($LASTEXITCODE -ne 0) {
throw "还原项目时出错:" + $project_file
}
.\msbuild $project_file /p:OutputPath=$output_path /p:Version=$version /v:m
if ($LASTEXITCODE -ne 0) {
throw "编译项目时出错:" + $project_file
}
.\msbuild -t:pack $project_file /p:Configuration=Release /p:OutputPath=$output_path /p:PackageOutputPath=$output_path /p:PackageVersion=$version /v:m
if ($LASTEXITCODE -ne 0) {
throw "打包项目时出错:" + $project_file
}
}
黑夜里不停折腾的代码行者。