如何将powershell exe调用转换为git CI/CD的YAML

如何将powershell exe调用转换为git CI/CD的YAML,powershell,gitlab,yaml,gitlab-ci,devops,Powershell,Gitlab,Yaml,Gitlab Ci,Devops,我很难理解yaml的语法。我想将下面的powershell命令转换为yaml,用于恢复nuget包和构建visualstudio解决方案。我不能得到正确的,请帮助 PowerShell命令: $ProjectPath = "e:\GitExperiment\SGen" Set-Location $ProjectPath $MSBuildPath = "C:\Program Files (x86)\Microsoft VisualStudio\2019\BuildTools\MSBuild\Cur

我很难理解yaml的语法。我想将下面的powershell命令转换为yaml,用于恢复nuget包和构建visualstudio解决方案。我不能得到正确的,请帮助

PowerShell命令:

$ProjectPath = "e:\GitExperiment\SGen"
Set-Location $ProjectPath
$MSBuildPath = "C:\Program Files (x86)\Microsoft VisualStudio\2019\BuildTools\MSBuild\Current\Bin"
$NugetExePath = "C:\Program Files (x86)\NuGet\nuget.exe"
& $NugetExePath restore $ProjectPath\SGen.sln
& $MSBuildPath\MSBuild.exe $ProjectPath\SGen.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:\GitExperiment\SGen"'
        - 'Set-Location $ProjectPath'
        - '$MSBuildPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe"'
        - '$NugetExePath = "C:\Program Files (x86)\NuGet\nuget.exe"'
        -  '"$NugetExePath restore $ProjectPath\SGen.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中使用引号、双引号和转义字符。但是没有正确的命令。 请帮忙。

如果是,我宁愿:

  • 将这些命令放在脚本中(与其他源代码一起进行版本控制)
  • 从YAML指令调用该脚本

    powershell -noprofile -noninteractive -executionpolicy Bypass -file my-script.ps1
    

这样,您就不必试图逃避任何特殊角色。

谢谢您的回答。正如你所建议的,我用命令创建了三个ps1文件来恢复nuget、构建和部署。将它们放在git上与yml文件相同的文件夹中。但是我得到了以下错误。$powershell-noprofile-noninteractive-executionpolicy Bypass-命令RestoreNuget.ps1 RestoreNuget.ps1:术语“RestoreNuget.ps1”无法识别为cmdlet、函数、脚本文件或可操作程序的名称。请检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。在第1行中,字符:1+RestoreNuget.ps1+~~~~~~~~~~~~~~~~~+CategoryInfo:ObjectNotFound:(RestoreNuget.ps1:String)[],CommandNotFoundException+FullyQualifiedErrorId:CommandNotFoundException@manjuv对不起,我已经编辑了我的答案:这应该是
-file
,而不是
-command
(请参见或作为示例)@曼珠夫太棒了!不要忘记阅读(关于这个,或者你过去的问题)