对于具有多个存储库的 Azure Pipeline,如何从签出的资源存储库中获取 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 Commit 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:
希望这可以帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)