我有一个config.ps1脚本,它有一个变量“$ versionNumber =”1.0.0“”。我需要输入用户选择的变量值并保存config.ps1文件。我需要使用Jenkins参数来完成这项任务。
我的config.ps1脚本。
#------------------------------------------------
# Pack parameters used to create the .nupkg file.
#------------------------------------------------
# Specify the Version Number to use for the NuGet package. If not specified, the version number of the assembly being packed will be used.
# NuGet version number guidance: https://docs.nuget.org/docs/reference/versioning and the Semantic Versioning spec: http://semver.org/
# e.g. "" (use assembly's version), "1.2.3" (stable version), "1.2.3-alpha" (prerelease version).
$versionNumber = "1.0.0"
# Specify any Release Notes for this package.
# These will only be included in the package if you have a .nuspec file for the project in the same directory as the project file.
$releaseNotes = ""
# Specify a specific Configuration and/or Platform to only create a NuGet package when building the project with this Configuration and/or Platform.
# e.g. $configuration = "Release"
# $platform = "AnyCPU"
$configuration = ""
$platform = ""
任何可行的方法都是可取的
我的方法 -
Get-Content c:\config.ps1 | ForEach-Object { $_ -replace "$versionNumber = "1.0.0"", "$versionNumber = "$env:version_number" }
输出
PS D:\> . .\Config.ps1
PS D:\> $versionNumber=1.0.2
PS D:\> $versionNumber
PS D:\> . .\Config.ps1
PS D:\> $versionNumber
1.0.0
PS D:\>
答案 0 :(得分:0)
您可以通过.
运算符获取* .ps1文件。例如:
Test.ps1
$test=1234
PS>. ./Test.ps1
PS> $test
1234
所以在你的Jenkins Powershell步骤中你可以致电:. PATHTO\config.ps1