Command/More/GetBuildDefinitions.ps1


Import-Module CmxModule -Force -DisableNameChecking
SetWindowTitle $MyInvocation.MyCommand.Name

# Get a build definition's drop location by its build definition string

function CmxGetDropFolderByBuildDefinitionTest
{
    <#
    .SYNOPSIS
    Get the drop folder of the most recent succeeded xaml build via the REST api.
    #>


    [CmdletBinding()]
    Param(
        [string]$DefinitionName
    )
    #Write-Host "the build definition name is $DefinitionName"
    
    $organizationUrl = $global:tfsUrl
    $tfsProject = "TIA Portal"
    $url = "$organizationUrl/$tfsProject"
    $argumentApiVersion = "api-version=1.0"
    $argumentStatus = "status=Succeeded"
    $argumentTop = "top=1"
    $uri = $url + '/_apis/build/builds?'
    $uri += $argumentApiVersion + '&'
    $uri += 'definition=' + $DefinitionName + '&'
    $uri += $argumentStatus + '&'
    $uri += $argumentTop + '&'
    $uri += 'ticks=' + (Get-Date).Ticks
    Write-Host "uri: $uri"
    #$response = (Invoke-RestMethod -Uri $uri -Method GET -UseDefaultCredentials)
    $credential = CmxGetWindowsCredential
    $response = (Invoke-RestMethod -Uri $uri -Method GET -Credential $credential)
    [array]$builds = $response.value
    $dropFolder = $builds[0].dropLocation
    return $dropFolder
}


$dropFolder = CmxGetDropFolderByBuildDefinitionTest -DefinitionName "TPE.Step7_Safety_T.Gated"
Write-Host "DropFolder2: $dropFolder"

# Write-Host "get xaml builds from rest api"
# $tfsServerURL = "https://jupiter.tfs.siemens.net/tfs/tia"
# $TFSProject = "TIA Portal"
# $BuildDefinition = "TPE.Step7_Safety_T.Gated"
# $URL = "$($tfsServerURL)/$($TFSProject)"
# $result = (Invoke-RestMethod -Uri ($URL + '/_apis/build/builds?api-version=1.0&definition=' + $BuildDefinition +'&status=Succeeded&$top=1') -Method GET -UseDefaultCredentials)
# $val = $result.value
# $dropLoc = $val.dropLocation
# Write-Host "Value: $val"
# Write-Host "dropLoc: $dropLoc"


# Write-Host "get the build defs from azure devops"
# $buildDefinitionsJson = az pipelines build list
# if($LastExitCode -eq 1)
# {
# Write-Host "The connection to azure failed."
# exit 1
# }
# $buildDefinitions = $buildDefinitionsJson | ConvertFrom-Json
# Write-Host "count: $($buildDefinitions.Count)"
# $name = $buildDefinitions[0].definition.name
# Write-Host "Build name: $name"
# $defs = $buildDefinitions | Where-Object {$_.controller -ne $null}
# $def = $desf[0]
# Write-Host "The name: $($def.definition.name)"

Read-Host "Press any key to exit"