共用方式為


steps.checkout 定義

使用 checkout 設定管線簽出原始程式碼的方式。

steps:
- checkout: string # Required as first property. Configures checkout for the specified repository.
  clean: true | false # If true, run git clean -ffdx followed by git reset --hard HEAD before fetching.
  fetchDepth: string # Depth of Git graph to fetch.
  fetchFilter: string # Filter Git history.
  fetchTags: string # Set to 'true' to sync tags when fetching the repo, or 'false' to not sync tags. See remarks for the default behavior.
  lfs: string # Set to 'true' to download Git-LFS files. Default is not to download them.
  persistCredentials: string # Set to 'true' to leave the OAuth token in the Git config after the initial fetch. The default is not to leave it.
  submodules: string # Set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules. Default is not to fetch submodules.
  path: string # Where to put the repository. The root directory is $(Pipeline.Workspace).
  sparseCheckoutDirectories: string # Directories for sparse checkout in cone mode and prioritized over sparseCheckoutPatterns if both properties are provided.
  sparseCheckoutPatterns: string # Patterns for sparse checkout in non-cone mode that are ignored if sparseCheckoutDirectories is provided.
  workspaceRepo: true | false # When true, use the repository root directory as the default working directory for the pipeline. The default is false.
  condition: string # Evaluate this condition expression to determine whether to run this task.
  continueOnError: boolean # Continue running even on failure?
  displayName: string # Human-readable name for the task.
  target: string | target # Environment in which to run this task.
  enabled: boolean # Run this task when the job runs?
  env: # Variables to map into the process's environment.
    string: string # Name/value pairs
  name: string # ID of the step.
  timeoutInMinutes: string # Time to wait for this task to complete before the server kills it.
  retryCountOnTaskFailure: string # Number of retries if the task fails.
steps:
- checkout: string # Required as first property. Configures checkout for the specified repository.
  clean: true | false # If true, run git clean -ffdx followed by git reset --hard HEAD before fetching.
  fetchDepth: string # Depth of Git graph to fetch.
  fetchTags: string # Set to 'true' to sync tags when fetching the repo, or 'false' to not sync tags. See remarks for the default behavior.
  lfs: string # Set to 'true' to download Git-LFS files. Default is not to download them.
  persistCredentials: string # Set to 'true' to leave the OAuth token in the Git config after the initial fetch. The default is not to leave it.
  submodules: string # Set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules. Default is not to fetch submodules.
  path: string # Where to put the repository. The root directory is $(Pipeline.Workspace).
  condition: string # Evaluate this condition expression to determine whether to run this task.
  continueOnError: boolean # Continue running even on failure?
  displayName: string # Human-readable name for the task.
  target: string | target # Environment in which to run this task.
  enabled: boolean # Run this task when the job runs?
  env: # Variables to map into the process's environment.
    string: string # Name/value pairs
  name: string # ID of the step.
  timeoutInMinutes: string # Time to wait for this task to complete before the server kills it.
  retryCountOnTaskFailure: string # Number of retries if the task fails.
steps:
- checkout: string # Required as first property. Configures checkout for the specified repository.
  clean: true | false # If true, run git clean -ffdx followed by git reset --hard HEAD before fetching.
  fetchDepth: string # Depth of Git graph to fetch.
  lfs: string # Set to 'true' to download Git-LFS files. Default is not to download them.
  persistCredentials: string # Set to 'true' to leave the OAuth token in the Git config after the initial fetch. The default is not to leave it.
  submodules: string # Set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules. Default is not to fetch submodules.
  path: string # Where to put the repository. The root directory is $(Pipeline.Workspace).
  condition: string # Evaluate this condition expression to determine whether to run this task.
  continueOnError: boolean # Continue running even on failure?
  displayName: string # Human-readable name for the task.
  target: string | target # Environment in which to run this task.
  enabled: boolean # Run this task when the job runs?
  env: # Variables to map into the process's environment.
    string: string # Name/value pairs
  name: string # ID of the step.
  timeoutInMinutes: string # Time to wait for this task to complete before the server kills it.
  retryCountOnTaskFailure: string # Number of retries if the task fails.
steps:
- checkout: string # Required as first property. Configures checkout for the specified repository.
  clean: true | false # If true, run git clean -ffdx followed by git reset --hard HEAD before fetching.
  fetchDepth: string # Depth of Git graph to fetch.
  lfs: string # Set to 'true' to download Git-LFS files. Default is not to download them.
  persistCredentials: string # Set to 'true' to leave the OAuth token in the Git config after the initial fetch. The default is not to leave it.
  submodules: string # Set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules. Default is not to fetch submodules.
  path: string # Where to put the repository. The root directory is $(Pipeline.Workspace).
  condition: string # Evaluate this condition expression to determine whether to run this task.
  continueOnError: boolean # Continue running even on failure?
  displayName: string # Human-readable name for the task.
  target: string | target # Environment in which to run this task.
  enabled: boolean # Run this task when the job runs?
  env: # Variables to map into the process's environment.
    string: string # Name/value pairs
  name: string # ID of the step.
  timeoutInMinutes: string # Time to wait for this task to complete before the server kills it.
steps:
- checkout: string # Required as first property. Whether or not to check out the repository containing this pipeline definition.
  clean: true | false # If true, run git clean -ffdx followed by git reset --hard HEAD before fetching.
  fetchDepth: string # Depth of Git graph to fetch.
  lfs: string # Set to 'true' to download Git-LFS files. Default is not to download them.
  persistCredentials: string # Set to 'true' to leave the OAuth token in the Git config after the initial fetch. The default is not to leave it.
  submodules: string # Set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules. Default is not to fetch submodules.
  path: string # Where to put the repository. The root directory is $(Pipeline.Workspace).
  condition: string # Evaluate this condition expression to determine whether to run this task.
  continueOnError: boolean # Continue running even on failure?
  displayName: string # Human-readable name for the task.
  enabled: boolean # Run this task when the job runs?
  env: # Variables to map into the process's environment.
    string: string # Name/value pairs
  name: string # ID of the step.
  timeoutInMinutes: string # Time to wait for this task to complete before the server kills it.
steps:
- checkout: string # Required as first property. Whether or not to check out the repository containing this pipeline definition.
  clean: true | false # If true, run git clean -ffdx followed by git reset --hard HEAD before fetching.
  fetchDepth: string # Depth of Git graph to fetch.
  lfs: string # Set to 'true' to download Git-LFS files. Default is not to download them.
  persistCredentials: string # Set to 'true' to leave the OAuth token in the Git config after the initial fetch. The default is not to leave it.
  submodules: string # Set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules. Default is not to fetch submodules.
  condition: string # Evaluate this condition expression to determine whether to run this task.
  continueOnError: boolean # Continue running even on failure?
  displayName: string # Human-readable name for the task.
  enabled: boolean # Run this task when the job runs?
  env: # Variables to map into the process's environment.
    string: string # Name/value pairs
  name: string # ID of the step.
  timeoutInMinutes: string # Time to wait for this task to complete before the server kills it.

參考此定義的定義:步驟

性能

checkout 字串。 做為第一個屬性的必要屬性。
設定指定存放庫的簽出。 指定 selfnone存放庫名稱存放庫資源。 如需詳細資訊,請參閱 查看管線中的多個存放庫

注意

如果沒有 checkout 步驟,預設為 jobs.job.step.checkoutselfnonejobs.deployment.steps.checkout

checkout 字串。 做為第一個屬性的必要屬性。
是否要簽出包含此管線定義的存放庫。 指定 selfnone

clean 字串。
如果為 true,請在擷取之前先執行 git clean -ffdx 後面接著 git reset --hard HEAD。 true |假。

fetchDepth 字串。
要擷取的 Git 圖形深度。

fetchFilter 字串。
使用 fetchFilter 篩選 Git 歷程記錄以進行部分複製。 fetchFilter 設定支援無樹狀和無 Blob 擷取。 針對無樹狀擷取,指定 fetchFilter: tree:0 並指定無 Blob 擷取,請指定 fetchFilter: blob:none。 預設值為無篩選。

fetchTags 字串。
在擷取存放庫時將 設定為 'true' 以同步標記,或將 'false' 設定為不會同步標記。 如需默認行為,請參閱備註。

lfs 字串。
設定為 'true' 以下載 Git-LFS 檔案。 預設值不是下載它們。

persistCredentials 字串。
設定為 'true' 以在初始擷取之後,將 OAuth 令牌保留在 Git 設定中。 預設值不是保留預設值。

submodules 字串。
針對單一層級的子模組或 『recursive』 設定為 『true』,以取得子模組的子模組。 預設值不是擷取子模組。

path 字串。
放置存放庫的位置。 根目錄為 $(Pipeline.Workspace)。 根據預設,此資料夾必須位在代理程式工作目錄結構之下。 若要設定代理程式工作目錄以外的路徑,請將名為 AZP_AGENT_ALLOW_WORK_DIRECTORY_REPOSITORIES 的管線變數設定為 true,並在簽出路徑開頭使用前置詞 ../。 代理程式 3.230.0 版和更新版本支援。

sparseCheckoutDirectories 字串。
指定目錄,以使用目錄比對在圓錐模式中啟用疏鬆簽出。 使用空格分隔多個目錄。

- checkout: repo
  sparseCheckoutDirectories: src

如果同時設定 sparseCheckoutDirectoriessparseCheckoutPatterns,則會使用 sparseCheckoutDirectories,並忽略 sparseCheckoutPatterns 的設定。

如需疏鬆結帳的詳細資訊,請參閱 使用疏鬆簽出將您的monorepo縮小為大小。

sparseCheckoutPatterns 字串。
指定模式,以使用模式比對在非圓錐模式中啟用疏鬆結帳。 使用空格分隔多個模式。

- checkout: repo
  sparseCheckoutPatterns: /* !/img

如果同時設定 sparseCheckoutDirectoriessparseCheckoutPatterns,則會使用 sparseCheckoutDirectories,並忽略 sparseCheckoutPatterns 的設定。

如需疏鬆結帳的詳細資訊,請參閱 使用疏鬆簽出將您的monorepo縮小為大小。

workspaceRepo 字串。
當為 true 時,請使用存放庫根目錄作為管線的預設工作目錄。 默認值為 false。

condition 字串。
評估此條件表示式,以判斷是否要執行這項工作。

continueOnError 布林值
即使在失敗時仍繼續執行?

displayName 字串。
工作的人類可讀取名稱。

target 目標
要在其中執行這項工作的環境。

enabled 布林值
作業執行時執行這項工作?

env 字串字典。
變數,以對應至進程的環境。

name 字串。
步驟的標識碼。 可接受的值:[-_A-Za-z0-9]*。

timeoutInMinutes 字串。
等候此工作在伺服器終止之前完成的時間。

注意

管線可能會設定作業層級逾時。 如果作業層級逾時間隔在步驟完成之前經過,即使步驟設定較長的 timeoutInMinutes 間隔,仍會終止執行中的作業(包括您的步驟)。 如需詳細資訊,請參閱 逾時

retryCountOnTaskFailure 字串。
如果工作失敗,重試次數。

言論

淺層

注意

在某些組織中,在 2022 年 9 月 2022 年 9 月 Azure DevOps 衝刺 209 更新之後建立的新管線預設會啟用淺層擷取,並設定深度為 1。 先前的預設值不是淺層擷取。

若要檢查管線,請在 管線設定 UI中檢視 淺層擷取 設定。

若要停用淺層擷取,您可以執行下列兩個選項之一。

  • 管線設定 UI中停用 淺層擷取 選項。
  • checkout 步驟中明確設定 fetchDepth: 0

若要設定管線的擷取深度,您可以在 checkout 步驟中設定 fetchDepth 屬性,或在 管線設定 UI中設定 淺層擷取 設定。

注意

如果您在 checkout 步驟中明確設定 fetchDepth,該設定會優先於管線設定 UI 中設定的設定。 設定 fetchDepth: 0 會擷取所有歷程記錄,並覆寫 淺層擷取 設定。

Clean 屬性

如果 clean 屬性未設定,則其預設值是由 YAML 管線 UI 設定中的 清除 設定所設定,預設設定為 true。 除了使用 checkout提供的清除選項之外,您也可以在工作區中設定清除。 如需工作區和清除選項的詳細資訊,請參閱 Jobs中的 工作區 主題。

同步標記

取出步驟會在擷取 Git 存放庫的內容時,使用 [--tags] 選項。 這會導致伺服器擷取所有標記,以及這些標記所指向的所有物件。 這會增加在管線中執行工作的時間,特別是如果您有一些標記的大型存放庫。 此外,即使啟用淺層擷取選項,簽出步驟也會同步處理標記,因而可能會破壞其目的。 若要減少從 Git 存放庫擷取或提取的數據量,Microsoft新增了簽出選項來控制同步標記的行為。 此選項可在傳統和 YAML 管線中使用。

簽出存放庫時,是否可以藉由設定 fetchTags 屬性,以及在UI中設定 同步處理標記 設定,以同步處理標記。

若要在 YAML 中設定設定,請設定 fetchTags 屬性。

steps:
- checkout: self
  fetchTags: true

若要在管線 UI 中設定設定,請編輯您的 YAML 管線,然後選擇 [其他動作]、[觸發程式]YAML[取得來源],然後核取或取消核取 [同步標記] 複選框。 如需詳細資訊,請參閱 同步標記

默認行為

  • 針對在 2022 年 9 月發行 Azure DevOps 短期衝刺 209之前建立的現有管線,同步標記的預設值會與新增 同步標記之前的現有行為相同, 選項,這是 true
  • 針對在 Azure DevOps 短期衝刺版本 209 之後建立的新管線,同步標記的預設值為 false

重要

同步標記 UI 中 true 的設定優先於 YAML 中的 fetchTags: false 語句。 如果在UI中 同步標記 設為 true,即使 YAML 中的 fetchTags 設為 false,也會同步標記。

例子

checkout有三個選項。 根據預設,Azure DevOps 會檢查目前存放庫,並針對作業 self。 當您設定 none時,不會取出任何存放庫。如果您指定另一個存放庫,則會取出該存放庫。若要簽出不同的存放庫,請先將它設定為 存放庫資源,

# Checkout the current repository
steps:
- checkout: self

# Prevent checking out any source code
steps:
- checkout: none

# Checkout a different repository
steps:
- checkout: my-other-repo

若要避免同步處理來源:

steps:
- checkout: none

注意

如果您是在本機服務帳戶中執行代理程式,而且想要使用 git 作業修改目前的存放庫,或載入 git 子模組,請為 Project Collection Build Service Accounts 使用者提供適當的許可權。

- checkout: self
  submodules: true
  persistCredentials: true

若要簽出管線中的多個存放庫,請使用多個 checkout 步驟:

- checkout: self
- checkout: git://MyProject/MyRepo
- checkout: MyGitHubRepo # Repo declared in a repository resource

如需詳細資訊,請參閱 查看管線中的多個存放庫

另請參閱