我一直在寻找使用Octopus API禁用个别流程步骤。我有一个包含10个步骤的项目,我使用TeamCity作为CI工具。所以我有一个条件,当我运行一个构建时,需要禁用一步(我想要的任何一个)。我想在宣传发布时禁用/跳过特定步骤。
我能够到达下面没有工作的步骤
Add-Type -Path 'Octopus.Client.dll'
$apikey = 'API-23H4GJ243HG2H3J423433H' # Get this from your profile
$octopusURI = 'http://localhost:9090' # Your server address
$projectName = "Demo" # Name of your project
$endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = new-object Octopus.Client.OctopusRepository $endpoint
$Header = @{ "X-Octopus-ApiKey" = $apikey }
$project = $repository.Projects.FindByName($projectName)
$deploymentProcess = $repository.DeploymentProcesses.Get($project.DeploymentProcessId)
foreach ($step in $deploymentProcess.Steps)
{
if($step.Name = "DemoStep")
{
$step.Actions.IsDisabled = 'True'
break
}
}
$repository.DeploymentProcesses.Modify($deploymentProcess)
或者
$Body = @{
IsDisabled = "True"
} | ConvertTo-Json
Invoke-RestMethod -Uri $OctopusURI/api/deploymentprocesses/deploymentprocess-Projects-21/ -Method PUT`
-Headers $Header -Body $Body
或者 Octo.exe --skip = stepname只适用于这种情况吗?
你能帮忙搞清楚吗?
谢谢, 姆兰
答案 0 :(得分:1)
我从八达通支持Support Link获得了禁用流程步骤的工作脚本,并且我扩展了该脚本以获得禁用和启用功能。
##SETUP##
$OctopusURL = ""
$APIKey = ""
$ProjectName = ""
$StepName = ""
$DesiredAction = "Enable" #Enable or Disable
##PROCESS#
Add-Type -Path 'Octopus.Client.dll'
$endpoint = new-object Octopus.Client.OctopusServerEndpoint $OctopusURL, $apikey
$repository = new-object Octopus.Client.OctopusRepository $endpoint
$Project = $repository.Projects.FindByName($ProjectName)
$deploymentProcess = $repository.DeploymentProcesses.Get($project.DeploymentProcessID)
$WasDeploymentProcessModified = $false
foreach ($step in $deploymentProcess.Steps) {
foreach ($Action in $step.actions) {
if ($Action.name -eq $StepName) {
"Step [$StepName] found"
if ($DesiredAction -eq "Disable") {
if ($Action.IsDisabled -eq $false) {
"Disabling step [$StepName]"
$Action.IsDisabled = $true
$WasDeploymentProcessModified = $true
}
Else {
"Step was already disabled"
}
}
elseif ($DesiredAction -eq "Enable") {
if ($Action.IsDisabled -eq $true) {
"Enabling step [$StepName]"
$Action.IsDisabled = $false
$WasDeploymentProcessModified = $true
}
Else {
"Step was already enabled"
}
}
}
}
}
if ($WasDeploymentProcessModified) {
"Steps in the deployment process of [$ProjectName] were changed. Saving changes to database..."
$repository.DeploymentProcesses.Modify($deploymentProcess)
}
else {
"No step was modified for [$ProjectName]"
}