Azure DevOps 服務 |Azure DevOps Server |Azure DevOps Server 2022 |Azure DevOps Server 2020
本文說明如何使用下列 az pipelines 命令來管理 Azure DevOps 專案中的現有管線:
- az pipelines list 用於列出專案中的管線
- az pipelines show 以顯示管線的詳細數據
- az pipelines run 以執行管道
- az pipelines update 用來更新管道
- az pipelines delete 來刪除管線
注意
Azure DevOps CLI 擴充功能僅適用於 Azure DevOps Services,且不支援任何版本的 Azure DevOps Server。
Azure DevOps CLI 延伸模組
命令az-pipelines群組是 Azure CLI 的 DevOps 延伸模組的一部分,需要 Azure CLI 2.30.0 版或更高版本。 Azure DevOps 擴充功能會在您第一次執行 azure pipelines 命令時自動安裝。 如需開始使用的詳細資訊,請參閱 開始使用 Azure DevOps CLI。
您也可以在 Azure DevOps CLI 命令中使用全域 Azure CLI 參數,例如 debug、help、only-show-errors、queryoutput、 和 verbose。
table全域參數的值--output會以易記格式呈現輸出。 如需詳細資訊,請參閱 Azure CLI 命令的輸出格式。
您可以使用 az devops configure --defaults organization=<YourOrganizationURL> 來設定 Azure DevOps CLI 命令的預設 Azure DevOps 組織,或使用 --detect true 參數來自動偵測組織。 您可以使用 az devops configure -d project=<Project Name or ID> 來設定預設的 Azure DevOps 專案。
如果您未偵測到組織或設定預設組織或專案,或透過 git config挑選組織和專案,您必須在每個命令中指定 org 和 project 參數。
列出現有的管線
您需要提供管線命令 run、show、update 和 delete,並且必須有您要管理的管線的 name 或 id。 如果您使用 id,則會忽略 name 參數。 若要取得專案管線的清單,包括其標識符,請使用 az pipelines list 命令。 您可以使用參數來篩選或格式化結果清單。
例如,下列命令會以數據表格式列出名稱開頭 python*為 的專案管線。
az pipelines list --name python* --output table
輸出:
ID Path Name Status Default Queue
---- ------ -------------------------- -------- ---------------
17 \ python-sample-vscode-flask disabled Azure Pipelines
24 \ python-sample-get-started enabled Azure Pipelines
如需完整的命令參考,請參閱 az pipelines list。
顯示管線的詳細數據
若要檢視現有管線的詳細數據,請使用 az pipelines show 命令。 例如,下列命令會顯示管線的詳細資訊與包含 ID 和 12 的內容,並在網頁瀏覽器中開啟管線摘要頁面。
az pipelines show --id 12 --open
如需完整的命令參考,請參閱 az pipelines show。
執行流程
若要將現有的管線排入佇列並執行,請使用 az pipelines run 命令。 您可以在執行中設定 parameters 和 variables 來使用。
例如,下列命令會在name分支中使用myGithubname.pipelines-javapipeline執行管線,將變數var1的值設定為100,並以table格式輸出結果。
az pipelines run --name myGithubname.pipelines-java --branch pipeline --variables var1=100 --output table
輸出:
Run ID Number Status Result Pipeline ID Pipeline Name Source Branch Queued Time Reason
-------- ---------- ---------- -------- ------------- --------------------------- --------------- -------------------------- --------
123 20200123.2 notStarted 12 myGithubname.pipelines-java pipeline 2020-01-23 11:55:56.633450 manual
如需完整的命令參考,請參閱 az pipelines run。
更新管線
若要更新現有的管線,請使用 az pipelines update 命令。 例如,下列命令會使用 id12 新的名稱和描述來更新 管線,並以數據表格式輸出結果。
az pipelines update --id 12 --description "rename pipeline" --new-name updatedname.pipelines-java --output table
輸出:
ID Name Status Default Queue
---- -------------------------- -------- ------------------
12 updatedname.pipelines-java enabled Hosted Ubuntu 1604
如需完整的命令參考,請參閱 az pipelines update。
刪除管線
若要刪除管線,請 執行 az-pipelines-delete 命令。 例如,下列命令會刪除標識碼為 12的管線,而且不會提示確認。 如果您未包含 --yes 參數,則命令預設會提示進行確認。
az pipelines delete --id 12 --yes
如需完整的命令參考,請參閱 az pipelines delete。
以程序設計方式建立和設定管線
若要使用 Azure DevOps CLI 建立 YAML 管線,請參閱 az pipelines create。 若要在 YAML 管線中執行 Azure CLI 命令,請參閱 Azure Pipelines YAML 中的 Azure DevOps CLI。
您可以建立 YAML 管線,以您選擇的語言建置、設定、測試及部署應用程式。 如需詳細資訊,請參閱下列文章:
- 建立、測試及部署 .NET Core 應用程式
- 建置及測試 Go 專案
- 建置 Java 應用程式
- 建置和發佈Node.js套件
- 建置和發佈 Python 應用程式
- 建置容器映像以部署應用程式
- 自訂您的管線
Azure DevOps Services REST API
您可以使用 REST API 進行直接 HTTP 呼叫,來建置與 Azure DevOps 整合的自定義應用程式或服務。 如需詳細資訊,請參閱 Azure DevOps Services REST API 參考。 您也可以針對這些 API 使用 用戶端連結庫 。
略過管線執行中的階段
您可以使用 az rest 命令搭配 執行管線 REST API,使用 stagesToSkip 參數略過管線執行中的階段。
例如:
az rest --method post `
--uri https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.1-preview.1 `
--body "{'stagesToSkip': [''], 'resources': {'repositories': {'self': {'refName': 'refs/heads/{branch}'}}}}" `
--resource 499b84ac-1321-427f-aa17-267ca6975798
如需詳細資訊,請參閱 搭配 Azure CLI 使用 Azure REST API。