I am currently working in azure DevOps and PowerShell. I need to build an azure pipeline through API using PowerShell. I have done something to list my projects in my organization. Kindly help me to build a pipeline through API similarly using PowerShell.
function GetUrl() {
param(
[string]$orgUrl,
[hashtable]$header,
[string]$AreaId
)
# Build the URL for calling the org-level Resource Areas REST API for the RM APIs
$orgResourceAreasUrl = [string]::Format("{0}/_apis/resourceAreas/{1}?api-preview=5.0-preview.1",
$orgUrl, $AreaId)
# Do a GET on this URL (this returns an object with a "locationUrl" field)
$results = Invoke-RestMethod -Uri $orgResourceAreasUrl -Headers $header
# The "locationUrl" field reflects the correct base URL for RM REST API calls
if ("null" -eq $results) {
$areaUrl = $orgUrl
}
else {
$areaUrl = $results.locationUrl
}
return $areaUrl
}
$orgUrl = "https://dev.azure.com/<my organization>/"
$personalToken = "<my path>"
Write-Host "Initialize authentication context" -ForegroundColor Yellow
$token =
[System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalToken)"))
$header = @{authorization = "Basic $token"}
$coreAreaId = "79134c72-4a58-4b42-976c-04e7115f32bf"
$tfsBaseUrl = GetUrl -orgUrl $orgUrl -header $header -AreaId $coreAreaId
$projectsUrl = "$($tfsBaseUrl)_apis/projects?api-version=5.0"
$projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -ContentType "application/json" -
Headers $header
$projects.value | ForEach-Object {
Write-Host $_.name
}
I have my output listing my projects while running this code.