powershell - 如何将 powershell exe 调用转换为 git CI/CD 的 YAML
问题描述
我很难理解 yaml 的语法。我想将以下用于恢复 nuget 包和构建 Visual Studio 解决方案的 power shell 命令转换为 yaml。我无法正确解决,请帮忙。
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 中使用引号和双引号以及转义字符。但无法正确执行命令。请帮忙。
解决方案
虽然gitlab-ci 跑步者确实支持 Powershell,但我宁愿:
- 将这些命令放在脚本中(与其余源一起版本化)
从您的 YAML 指令中调用该脚本
powershell -noprofile -noninteractive -executionpolicy Bypass -file my-script.ps1
这样,您就不必处理试图转义任何特殊字符的问题。
推荐阅读
- javascript - JavaScript 函数没有返回正确的数据
- solr - Solr 8.2.0 无法在云模式下启动
- python - 初始化 numpy 数组的不同方法。哪个是哪个?
- c - 如何将无符号字符转换为二进制表示
- javascript - 将视口上的部分存储为变量值 - jQuery
- x86 - 如何获得物理内存的实际大小?
- node.js - 用于休息 api 的 typegoose/mongoose 日期格式
- xamarin.forms - Xamarin 自定义控件未显示在工具箱中
- python - matplotlib中的axes加倍,我只能摆脱一组
- android - 从 android 到自定义套接字服务器的 SSL/TLS 连接