对于具有多存储库的 Azure Pipeline,如何从 checkout 的资源存储库中获取 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
最佳答案
how can you get the GIT commit id from a checked out resource repository? Is it supported?
恐怕目前 Azure devops 不支持这一点。
因此,我们无法使用 $(Build.SourceVersion)
等预定义变量直接从多存储库获取 Git Commit 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
作业 B
的结果:
来自 bitbucket.org 的 Commit Id:
希望这对您有所帮助。
关于git - Azure Pipelines 多存储库如何获取 Git 提交 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62156628/