【发布时间】:2016-06-07 22:31:38
【问题描述】:
我正在使用 Octopus deploy 在目标计算机上运行 PowerShell 脚本,尝试安装 IIS。我正在使用下面的脚本并传入必要的参数。记录的内容让人相信调用正确,但它只是响应:
正在从Chocolatey 包存储库安装包IIS-WebServerRole...
17:11:48Info
Installing the following packages:
17:11:48Info
IIS-WebServerRole
17:11:48Info
By installing you accept licenses for the packages.
17:11:48Info
IIS-WebServerRole not installed. The package was not found with the source(s) listed.
17:11:48Info
If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.
17:11:48Info
Version: ""
17:11:48Info
Source(s): "windowsFeatures"
代码:
$chocolateyBin = [Environment]::GetEnvironmentVariable("ChocolateyInstall", "Machine") + "\bin"
if(-not (Test-Path $chocolateyBin)) {
Write-Output "Environment variable 'ChocolateyInstall' was not found in the system variables. Attempting to find it in the user variables..."
$chocolateyBin = [Environment]::GetEnvironmentVariable("ChocolateyInstall", "User") + "\bin"
}
$cinst = "$chocolateyBin\cinst.exe"
$choco = "$chocolateyBin\choco.exe"
if (-not (Test-Path $cinst) -or -not (Test-Path $choco)) {
throw "Chocolatey was not found at $chocolateyBin."
}
if (-not $ChocolateyPackageId) {
throw "Please specify the ID of an application package to install."
}
$chocoVersion = & $choco --version
Write-Output "Running Chocolatey version $chocoVersion"
$chocoArgs = @()
if([System.Version]::Parse($chocoVersion) -ge [System.Version]::Parse("0.9.8.33")) {
Write-Output "Adding --confirm to arguments passed to Chocolatey"
$chocoArgs += @("-y", "")
}
if($ChocolateyPackageSource) {
Write-Output "Adding --source to arguments passed to Chocolatey"
$chocoArgs += @("-source", $ChocolateyPackageSource)
}
if (-not $ChocolateyPackageVersion) {
Write-Output "Installing package $ChocolateyPackageId from the Chocolatey package repository..."
& $cinst $ChocolateyPackageId $($chocoArgs)
} else {
Write-Output "Installing package $ChocolateyPackageId version $ChocolateyPackageVersion from the Chocolatey package repository..."
& $cinst $ChocolateyPackageId -version $ChocolateyPackageVersion $($chocoArgs)
}
根据我能找到的最新 Chocolatey 文档,这应该可行。任何想法为什么它不会?我应该提到这是在 Azure Windows 2012 R2 VM 上。
【问题讨论】:
-
你能不能在盒子上运行一个 powershell 脚本,以运行触手的用户身份手动运行?
-
@AlexM - 是的,即使我以管理员身份登录机器,我也会收到完全相同的消息。似乎 Windows 功能命令不起作用。我什至尝试了一些旧版本的调用,它们也不起作用。我刚开始使用 Chocolatey,所以我想也许我做错了什么。
标签: powershell octopus-deploy chocolatey