gpt4 book ai didi

rest - 在 TeamCity 中禁用构建步骤或在特定步骤开始运行的脚本

转载 作者:行者123 更新时间:2023-12-01 11:27:18 26 4
gpt4 key购买 nike

我想在 TeamCity 配置中禁用几个构建步骤。
例如:

  • I have a deploy configuration called DeploySoftware.
  • It has 10 build steps (Run >DB scripts, Run environment scripts, Deploy Web Service, Deploy Windows Service, Deploy This, Deploy That, etc).
  • I run it once and it fails on Deploy This.
  • I want to run it again starting with Deploy This, OR disable all the previous steps to that one by using a script.


我的一个配置有 30 个构建步骤,所以如果它在第 28 步失败(并且我知道另一次运行很可能会成功),我想从第 28 步开始再次运行它。否则它是 45 分钟的运行步骤已经成功完成,在我到达需要运行的步骤之前。

我不需要脚本来运行构建(虽然这很好),或者在运行后将配置更改回(我希望这将是对禁用脚本的简单调整)。

脚本可以是 PowerShell、C#、VB.NET、VBA、Ruby - 几乎任何我可以快速修改和运行的东西。

最佳答案

以下脚本将从 1 => x 禁用或启用构建步骤

# -----------------------------------------------
# Build Step Disabler
# -----------------------------------------------
#
# Ver Who When What
# 1.0 Evolve Software Ltd 29-03-16 Initial Version

# Script Input Parameters
param (
[ValidateNotNullOrEmpty()]
[string] $RestEndPoint = $(throw "-RestEndPoint is mandatory, please provide a value."),
[ValidateNotNullOrEmpty()]
[string] $ApiUsername = $(throw "-ApiUsername is mandatory, please provide a value."),
[ValidateNotNullOrEmpty()]
[string] $ApiPassword = $(throw "-ApiPassword is mandatory, please provide a value."),
[ValidateNotNullOrEmpty()]
[int] $FailedStep = $(throw "-FailedStep is mandatory, please provide a value."),
[bool] $Disable = $True
)

function Main()
{
$CurrentScriptVersion = "1.0"
$ApiCredentials = New-Object System.Management.Automation.PSCredential($ApiUsername, (ConvertTo-SecureString $ApiPassword -AsPlainText -Force))

$ApiCredentials_ForHeader = $ApiUsername + ":" + $ApiPassword
$ApiCredentialsBase64 = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($ApiCredentials_ForHeader))

$ApiCredentialsHeader = @{};
$ApiCredentialsHeader.Add("Authorization", "Basic $ApiCredentialsBase64")

Write-Host "================== Build Step Disabler - Version"$CurrentScriptVersion": START =================="

# Log input variables passed in
Log-Variables
Write-Host

# Get the steps into XML
[System.Xml.XmlDocument]$stepsResponse = Api-Get "$RestEndPoint/steps"
$currentStep = 1;

do {
try {
[System.Xml.XmlElement]$step = $stepsResponse.steps.step[$currentStep-1]

if (!$step.id)
{
Write-Output "Build step id not found - Exiting"
Exit 1
}

$stepId = $step.id
Api-Put "$RestEndPoint/steps/$stepId/disabled" ($Disable).ToString().ToLower()
$currentStep++
}
catch [System.Exception] {
Write-Output $_
Write-Output "Unable to configure the build steps correctly"
Exit 1
}
}
while ($currentStep -le $FailedStep)

Write-Host "================== Build Step Disabler - Version"$CurrentScriptVersion": END =================="
}

function Log-Variables
{
Write-Host "RestEndPoint: " $RestEndPoint
Write-Host "FailedStep: " $FailedStep
Write-Host "Disable: " $Disable
Write-Host "Computername:" (gc env:computername)
}

function Api-Get($Url)
{
Write-Host $Url
return Invoke-RestMethod -Headers $ApiCredentialsHeader -Credential $ApiCredentials -Uri $Url -Method Get -ContentType "application/xml" -TimeoutSec 30;
}

function Api-Put($Url, $Data)
{
Write-Host $Url
return Invoke-RestMethod -Headers $ApiCredentialsHeader -Credential $ApiCredentials -Uri $Url -Method Put -ContentType "text/plain" -Body $Data -TimeoutSec 30 -DisableKeepAlive;
}

Main

用法 :

这将禁用构建步骤 1 => 5
script.ps1 "http://teamcity/httpAuth/app/rest/buildTypes/DeploySoftware" username password 5

这将启用构建步骤 1 => 5
script.ps1 "http://teamcity/httpAuth/app/rest/buildTypes/DeploySoftware" username password 5 $false

希望这可以帮助

关于rest - 在 TeamCity 中禁用构建步骤或在特定步骤开始运行的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36279117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com