【问题标题】:Chocolatey can't find windows featureChocolatey找不到Windows功能
【发布时间】: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


【解决方案1】:

我可以通过使用 Chocolatey 的预发布版本来完成这项工作。 9.10.x-beta...

我应该注意,仅执行 -pre 还不足以让它安装包...由于某种原因,我还必须 -force 包以巧克力色进行自我更新。不确定这是否是设计使然。

【讨论】:

  • 绝对不是设计使然。如果您有任何日志无法正常工作,我很想看看。旁注,choco upgrade chocolatey -pre,不是choco install chocolatey -pre/cinst chocolatey -pre。后两个命令需要--force,因为安装是关于安装某些东西,升级是从那时起。 HTH。让我知道是否还有其他问题。
  • 我确实确认我正在升级......不知道为什么需要强制,如果我再次这样做,我会发送一些日志。
  • 酷 - 请记住日志是以调试/详细格式获取的。因此,当您想查看时,这会很有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-23
  • 2020-03-31
  • 2018-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多