Azure Pipelines multi-repo如何获取Git提交ID

问题描述 投票:0回答:1

对于具有多个存储库的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 bitbucket azure-pipelines delphi-xe
1个回答
0
投票

如何从已检出的资源库中获取GIT提交ID?支持吗?

恐怕Azure开发人员目前不支持此功能。

因此,我们不能使用预定义变量(例如$(Build.SourceVersion))直接从多个存储库获取Git提交ID。

要解决此问题,我们可以使用git命令行获取Commit 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

[C0的结果:

job B

从bitbucket.org提交ID:

enter image description here

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.