簡體   English   中英

Azure Pipelines multi-repo 如何獲取 Git Commit ID

[英]Azure Pipelines multi-repo how to get Git Commit ID

對於具有多個存儲庫的 Azure 管道,如何從簽出的資源存儲庫中獲取 GIT 提交 ID? 是否支持?

我正在使用 Azure 存儲庫來存儲管道 yaml 文件,並檢查代理上的構建源以在那里構建。 我們正在使用 Delphi 所以我們必須使用代理。

resources:
  repositories:
  - repository: MyBitBucketRepo
    type: bitbucket
    endpoint: MyBitBucketServiceConnection
    name: MyBitBucketOrgOrUser/MyBitBucketRepo

trigger:
- pilot

pool:
  name: MyAgent
  demands: RADSTUDIO

variables:
  GIT_COMMIT: $(Build.SourceVersion) # <- How can I get the checked out Commit ID for the MyBitBucketRepo?
  GIT_BRANCH: $(Build.SourceBranchName) # And the branch name?

steps:
- checkout: MyBitBucketRepo

- script: dir $(Build.SourcesDirectory)
- script: echo $(GIT_COMMIT)
- script: echo $(GIT_BRANCH)
# todo set environment vars on agent with the Commit and Branch names required by msbuild script on agent
# todo run msbuild script on agent

如何從簽出的資源庫中獲取 GIT 提交 ID? 是否支持?

恐怕目前 Azure devops 不支持這一點。

因此,我們無法使用$(Build.SourceVersion)等預定義變量直接從多存儲庫中獲取 Git 提交 ID。

為了解決這個問題,我們可以使用 git 命令行來獲取提交 ID 和分支名稱:

 git rev-parse HEAD
 git branch -r

您可以查看我的測試 YAML 文件了解一些詳細信息:

resources:
  repositories:
  - repository: TestProject
    type: github
    name: xxxx/TestProject
    endpoint: GitHub connection 1
  - repository: leotest
    type: bitbucket
    name: Lsgqazwsx/leotest
    endpoint: Lsgqazwsx

variables:
  GIT_COMMIT: $(Build.SourceVersion)
  GIT_BRANCH: $(Build.SourceBranchName)


stages:
- stage:
  jobs:
   - job: A
     pool:
       name: MyPrivateAgent
     steps:
     - checkout: TestProject
     - script: echo $(GIT_COMMIT)

- stage:
  jobs:
   - job: B
     pool:
      name: MyPrivateAgent
     steps:
     - checkout: leotest
     - script: git rev-parse HEAD
     - script: git branch -r

job B的結果:

在此處輸入圖像描述

來自 bitbucket.org 的提交 ID:

在此處輸入圖像描述

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM