安装 IIS 作为 Octopus Deploy 中的一个步骤
Installing IIS as a step in Octopus Deploy
我正在尝试向我的 Octopus Deployment
添加一个步骤,如果 IIS 未安装在目标上,该步骤将安装 IIS,但我找不到任何东西。如果目前没有任何东西,是否有我可以使用的 powershell 脚本将 Web Server (IIS)
角色/功能添加到机器?
这将使启动安装了最少功能的新虚拟机变得更加容易,然后在部署特定应用程序时,他们可以管理是否需要 IIS,而不是手动将其添加到适当的机器。
提前致谢!
您可以使用 Enable-WindowsOptionalFeature
或 Install-WindowsFeature
,具体取决于您正在配置的机器。快速 Google 搜索引导我 here
下面是检查IIS是否安装的例子,如果没有就安装
if ((Get-WindowsFeature Web-Server).InstallState -eq "Installed") {
Write-Host "IIS is installed on $vm"
}
else {
Write-Host "IIS is not installed on $vm"
Write-Host "Installing IIS.."
Install-WindowsFeature -name Web-Server -IncludeManagementTools
}
在深入了解 Octopus 上可用的模板后,我刚刚找到了一个解决方案,WesleySSmith
有一个名为 Windows - Ensure Features Installed
的步骤模板,可以将其添加到您的流程中。它允许您提供要安装的功能名称,例如 IIS-WebServer
.
对于 PowerShell 狂热者,目前这一步背后的脚本如下所示:
$requiredFeatures = $OctopusParameters['WindowsFeatures'].split(",") | foreach {
$_.trim() }
if(! $requiredFeatures) {
Write-Output "No required Windows Features specified..."
exit
}
$requiredFeatures | foreach { $feature = DISM.exe /ONLINE /Get-FeatureInfo /FeatureName:$_; if($feature -like "*Feature name $_ is unknown*") { throw $feature } }
Write-Output "Retrieving all Windows Features..."
$allFeatures = DISM.exe /ONLINE /Get-Features /FORMAT:List | Where-Object { $_.StartsWith("Feature Name") -OR $_.StartsWith("State") }
$features = new-object System.Collections.ArrayList
for($i = 0; $i -lt $allFeatures.length; $i=$i+2) {
$feature = $allFeatures[$i]
$state = $allFeatures[$i+1]
$features.add(@{feature=$feature.split(":")[1].trim();state=$state.split(":")[1].trim()}) | OUT-NULL
}
Write-Output "Checking for missing Windows Features..."
$missingFeatures = new-object System.Collections.ArrayList
$features | foreach { if( $requiredFeatures -contains $_.feature -and $_.state -eq 'Disabled') { $missingFeatures.add($_.feature) | OUT-NULL } }
if(! $missingFeatures) {
Write-Output "All required Windows Features are installed"
exit
}
Write-Output "Installing missing Windows Features..."
$featureNameArgs = ""
$missingFeatures | foreach { $featureNameArgs = $featureNameArgs + " /FeatureName:" + $_ }
$dism = "DISM.exe"
IF ($SuppressReboot)
{
$arguments = "/NoRestart "
}
ELSE
{
$arguments = ""
}
$arguments = $arguments + "/ONLINE /Enable-Feature $featureNameArgs"
IF ($Source)
{
if (!(Test-Path $Source)) {
throw "Could not find the file $Source or access denied"
}
$arguments = $arguments + " /Source:$Source"
}
Write-Output "Calling DISM with arguments: $arguments"
start-process -NoNewWindow $dism $arguments
我正在尝试向我的 Octopus Deployment
添加一个步骤,如果 IIS 未安装在目标上,该步骤将安装 IIS,但我找不到任何东西。如果目前没有任何东西,是否有我可以使用的 powershell 脚本将 Web Server (IIS)
角色/功能添加到机器?
这将使启动安装了最少功能的新虚拟机变得更加容易,然后在部署特定应用程序时,他们可以管理是否需要 IIS,而不是手动将其添加到适当的机器。
提前致谢!
您可以使用 Enable-WindowsOptionalFeature
或 Install-WindowsFeature
,具体取决于您正在配置的机器。快速 Google 搜索引导我 here
下面是检查IIS是否安装的例子,如果没有就安装
if ((Get-WindowsFeature Web-Server).InstallState -eq "Installed") {
Write-Host "IIS is installed on $vm"
}
else {
Write-Host "IIS is not installed on $vm"
Write-Host "Installing IIS.."
Install-WindowsFeature -name Web-Server -IncludeManagementTools
}
在深入了解 Octopus 上可用的模板后,我刚刚找到了一个解决方案,WesleySSmith
有一个名为 Windows - Ensure Features Installed
的步骤模板,可以将其添加到您的流程中。它允许您提供要安装的功能名称,例如 IIS-WebServer
.
对于 PowerShell 狂热者,目前这一步背后的脚本如下所示:
$requiredFeatures = $OctopusParameters['WindowsFeatures'].split(",") | foreach {
$_.trim() }
if(! $requiredFeatures) {
Write-Output "No required Windows Features specified..."
exit
}
$requiredFeatures | foreach { $feature = DISM.exe /ONLINE /Get-FeatureInfo /FeatureName:$_; if($feature -like "*Feature name $_ is unknown*") { throw $feature } }
Write-Output "Retrieving all Windows Features..."
$allFeatures = DISM.exe /ONLINE /Get-Features /FORMAT:List | Where-Object { $_.StartsWith("Feature Name") -OR $_.StartsWith("State") }
$features = new-object System.Collections.ArrayList
for($i = 0; $i -lt $allFeatures.length; $i=$i+2) {
$feature = $allFeatures[$i]
$state = $allFeatures[$i+1]
$features.add(@{feature=$feature.split(":")[1].trim();state=$state.split(":")[1].trim()}) | OUT-NULL
}
Write-Output "Checking for missing Windows Features..."
$missingFeatures = new-object System.Collections.ArrayList
$features | foreach { if( $requiredFeatures -contains $_.feature -and $_.state -eq 'Disabled') { $missingFeatures.add($_.feature) | OUT-NULL } }
if(! $missingFeatures) {
Write-Output "All required Windows Features are installed"
exit
}
Write-Output "Installing missing Windows Features..."
$featureNameArgs = ""
$missingFeatures | foreach { $featureNameArgs = $featureNameArgs + " /FeatureName:" + $_ }
$dism = "DISM.exe"
IF ($SuppressReboot)
{
$arguments = "/NoRestart "
}
ELSE
{
$arguments = ""
}
$arguments = $arguments + "/ONLINE /Enable-Feature $featureNameArgs"
IF ($Source)
{
if (!(Test-Path $Source)) {
throw "Could not find the file $Source or access denied"
}
$arguments = $arguments + " /Source:$Source"
}
Write-Output "Calling DISM with arguments: $arguments"
start-process -NoNewWindow $dism $arguments