steps.checkout 定義

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

steps:
- checkout: string # Required as first property. Configures checkout for the specified repository.
  clean: string # 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: string # 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: string # 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: string # 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: string # 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如果沒有步驟存在,則會針對 和 none 預設 selfjobs.job.step.checkoutjobs.deployment.steps.checkout

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

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

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

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

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

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

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

path 字串。
放置存放庫的位置。 根目錄是 $ (Pipeline.Workspace) 。

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

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

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

targettarget
執行這項工作的環境。

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

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

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

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

注意

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

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

備註

淺層

重要

在 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 的清除選項之外,您也可以在工作區中設定清除。 如需工作區和清除選項的詳細資訊,請參閱作業中的工作區主題。

同步標記

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

簽出存放庫時是否要同步處理標籤,方法是設定 fetchTags 屬性,以及在 UI 中設定 同步標記 設定。

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

steps:
- checkout: self
  fetchTags: true

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

預設行為

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

重要

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

範例

若要避免同步處理來源:

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

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

另請參閱