You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何搜索Azure DevOps流水线?非YAML类型未存储仓库流水线检索及重构需求咨询

How to Search for Azure DevOps Pipelines (Classic, Non-YAML, Non-Repo Stored)

Got it, let's break down how you can track down those classic (non-YAML, not stored in code repos) Azure DevOps pipelines with repetitive bash script snippets you need to refactor. Here are practical, actionable methods:

1. Use the Azure DevOps REST API to Scan Pipeline Definitions

Classic pipelines are stored directly in Azure DevOps (not your repo), so the REST API is your best bet to pull their full definitions and search for specific content.

Step-by-Step:

  • List all classic pipelines in your organization/project:
    Call this endpoint to get all pipelines, then filter for classic ones (identified by configuration.type = designer):

    GET https://dev.azure.com/{your-org}/{your-project}/_apis/pipelines?api-version=7.1-preview.1
    

    Parse the JSON response to collect all id values where configuration.type is designer—these are your classic pipelines.

  • Fetch full definitions for each classic pipeline:
    For each pipeline ID you collected, use this endpoint to get detailed build definitions including all steps and script content:

    GET https://dev.azure.com/{your-org}/{your-project}/_apis/build/definitions/{pipeline-id}?api-version=7.1-preview.7
    

    In the response, look under process.phases.steps array. For bash tasks, you'll see entries where task.name equals Bash, and the script content lives in task.inputs.script.

  • Search for your target bash snippets:
    Write a simple script (Python, PowerShell, etc.) to parse these JSON responses and check if the script field contains the copy-pasted code you're targeting. Collect the pipeline name and ID whenever a match is found.

2. PowerShell Script for Bulk Scanning

If you prefer automation, a PowerShell script can handle the entire scanning workflow. Here's a simplified example (using a personal access token for authentication):

# Set your variables
$orgUrl = "https://dev.azure.com/your-org"
$projectName = "your-project"
$pat = "your-personal-access-token"
$targetSnippet = "your-copy-pasted-bash-code-snippet"

# Encode PAT for authentication
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat"))

# Get all classic pipelines
$pipelinesUrl = "$orgUrl/$projectName/_apis/pipelines?api-version=7.1-preview.1"
$pipelines = Invoke-RestMethod -Uri $pipelinesUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Get
$classicPipelines = $pipelines.value | Where-Object { $_.configuration.type -eq "designer" }

# Scan each classic pipeline for the target snippet
foreach ($pipeline in $classicPipelines) {
    $defUrl = "$orgUrl/$projectName/_apis/build/definitions/$($pipeline.id)?api-version=7.1-preview.7"
    $definition = Invoke-RestMethod -Uri $defUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Get
    
    # Check all bash steps for the target snippet
    $bashSteps = $definition.process.phases.steps | Where-Object { $_.task.name -eq "Bash" }
    foreach ($step in $bashSteps) {
        if ($step.task.inputs.script -match $targetSnippet) {
            Write-Host "Match found in pipeline: $($pipeline.name) (ID: $($pipeline.id))"
            break
        }
    }
}

Replace the placeholders with your org, project, PAT, and the bash snippet you're searching for, then run the script to get your list of pipelines to refactor.

3. Use Azure DevOps Analytics to List Classic Pipelines First

If you want a quick overview before deep scanning, use Analytics Views:

  • Go to your Azure DevOps project, navigate to Analytics > Views > New View.
  • Select Builds as the view type, then add a filter: Definition Type equals Classic.
  • Add columns like Definition Name, Definition ID, and Created Date to the view.
  • Export the view to a CSV file. Use this list to prioritize pipelines to scan, or feed it into your API/script workflow to target specific candidates.

4. Portal Search (Limited Use)

The Azure DevOps portal's search bar can help find pipelines by name, but it won't search inside pipeline definitions. If you know part of the pipeline name tied to the bash snippets, this can be a quick way to narrow down candidates before using the more thorough API/script methods.


Once you've compiled your list, you can go through each pipeline to refactor repetitive bash steps into external scripts. This approach ensures you don't miss any instances that need updating.

内容的提问来源于stack exchange,提问作者gaccardo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 21:52:29