Hea*_*vyg 4 continuous-deployment azure-devops
我有一个工作服务应用程序,我通过复制其二进制文件并使用 PowerShell 通过“New-Service”命令进行安装,在开发服务器上手动安装该应用程序。
我们正在寻找 CI/CD 来自动化构建和部署其工件。我不知道如何将“构建”文件从 Azure 获取到本地服务器,我已经查看了诸如部署组之类的内容,但这些似乎不是用于复制的发布工具中的选项。我已经查看了“复制”工具和构建工具,但我被困住了。
有些人似乎使用“经典”提到这一点,我想我使用的是 YAML,但不是经典。
有人能指出我正确的方向吗?
使用经典 UI 对我来说更简单(最后也是 YAML)
你需要的是:
以及安装 Windows 服务的一些帮助(您可以执行此任务,但类似的任务已经存在)
$serviceName = "$(ServiceName)"
$serviceDisplayName = "$(ServiceDisplayName)"
$serviceDescription = "$(ServiceDescription)"
$exePath = "$(ServiceExeFullPath)"
$username = "NT AUTHORITY\NETWORK SERVICE"
$password = convertto-securestring -String "dummy" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
Write-Host "====================================="
Write-Host $serviceName
Write-Host $serviceDisplayName
Write-Host $serviceDescription
Write-Host $exePath
Write-Host "====================================="
$existingService = Get-WmiObject -Class Win32_Service -Filter "Name='$serviceName'"
if ($existingService)
{
"'$serviceName' exists already. Stopping."
Stop-Service $serviceName
"Waiting 5 seconds to allow existing service to stop."
Start-Sleep -s 5
"Seting new binpath for the service '$serviceName'"
sc.exe config $serviceName binpath= $exePath
"Waiting 5 seconds to allow service to be re-configured."
Start-Sleep -s 5
}
else
{
"Installing the service '$serviceName'"
New-Service -BinaryPathName $exePath -Name $serviceName -Credential $cred -DisplayName $serviceDisplayName -Description $serviceDescription -StartupType Automatic
"Service installed"
"Waiting 5 seconds to allow service to be installed."
Start-Sleep -s 5
}
"Starting the service."
Start-Service $serviceName
"Completed."
Run Code Online (Sandbox Code Playgroud)
像“$(ServiceName)”这样的变量是从 AzureDevops 发布变量中替换的。您可以在此处阅读有关变量用法的更多信息
设置常用服务选项也可能很有用。我通常通过单独的 powershell 任务来完成此操作:
$serviceName = "$(ServiceName)"
$failureDelay = [int] $(ServiceFailureDelayMs)
$failureAction = "restart"
$reset = [int] $(ServiceResetSeconds)
$service = Get-Service $serviceName -ErrorAction SilentlyContinue
if(!$service)
{
Write-Host "##vso[task.LogIssue type=warning;]Directory Windows Service '$serviceName' not found, skip."
return
}
"Updating '$serviceName' service recovery options."
sc.exe failure $service.Name actions= $failureAction/$failureDelay/$failureAction/$failureDelay/$failureAction/$failureDelay reset= $reset
"Done."
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2864 次 |
| 最近记录: |