我很难理解yaml的语法。我想将下面的powershell命令转换为yaml,用于恢复nuget包和构建visualstudio解决方案。我无法纠正,请帮忙。
PowerShell通讯:
$ProjectPath = "e:GitExperimentSGen"
Set-Location $ProjectPath
$MSBuildPath = "C:Program Files (x86)Microsoft VisualStudio2019BuildToolsMSBuildCurrentBin"
$NugetExePath = "C:Program Files (x86)NuGetnuget.exe"
& $NugetExePath restore $ProjectPathSGen.sln
& $MSBuildPathMSBuild.exe $ProjectPathSGen.sln /t:Build /p:Configuration=Release /p:TargetFramework=v4.7.2 /p:SkipPostSharp=True /p:RunCodeAnalysis=False
YAML
stages:
- BUILD
- UNITTEST
- DEPLOY
BUILD_RestoreNugetPackages:
script:
- '$ProjectPath = e:GitExperimentSGen"'
- 'Set-Location $ProjectPath'
- '$MSBuildPath = "C:Program Files (x86)Microsoft Visual Studio2019BuildToolsMSBuildCurrentBinMSBuild.exe"'
- '$NugetExePath = "C:Program Files (x86)NuGetnuget.exe"'
- '"$NugetExePath restore $ProjectPathSGen.sln"'
stage: BUILD
tags:
- ci
BUILD_SolutionBuild:
script:
- "& $MSBuildPath $ProjectPath\SGen.sln /t:Build /p:Configuration=Release /p:TargetFramework=v4.7.2 /p:SkipPostSharp=True /p:RunCodeAnalysis=False"
stage: BUILD
tags:
- ci
我尝试在yaml中使用引号、双引号和转义字符。但无法正确执行命令。请帮忙。
虽然gitlab ci runner确实支持Powershell,但我宁愿:
- 将这些命令放在脚本中(与其他源一起进行版本控制(
-
从YAML指令调用该脚本
powershell -noprofile -noninteractive -executionpolicy Bypass -file my-script.ps1
这样,您就不必试图转义任何特殊字符。