jan*_*170 7 git bitbucket delphi-xe azure-pipelines
对于具有多个存储库的 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
Run Code Online (Sandbox Code Playgroud)
\n\n\n如何从签出的资源存储库中获取 GIT 提交 ID?支持吗?
\n
恐怕目前 Azure DevOps 还不支持这一点。
\n\n因此,我们无法使用预定义的变量,例如$(Build.SourceVersion)直接从多存储库获取 Git Commit ID。
为了解决这个问题,我们可以使用 git 命令行来获取提交 ID 和分支名称:
\n\n git rev-parse HEAD\n git branch -r\nRun Code Online (Sandbox Code Playgroud)\n\n您可以检查我的测试 YAML 文件以获取一些详细信息:
\n\nresources:\n repositories:\n - repository: TestProject\n type: github\n name: xxxx/TestProject\n endpoint: GitHub connection 1\n - repository: leotest\n type: bitbucket\n name: Lsgqazwsx/leotest\n endpoint: Lsgqazwsx\n\nvariables:\n GIT_COMMIT: $(Build.SourceVersion)\n GIT_BRANCH: $(Build.SourceBranchName)\n\n\nstages:\n- stage:\n jobs:\n - job: A\n pool:\n name: MyPrivateAgent\n steps:\n - checkout: TestProject\n - script: echo $(GIT_COMMIT)\n\n- stage:\n jobs:\n - job: B\n pool:\n name: MyPrivateAgent\n steps:\n - checkout: leotest\n - script: git rev-parse HEAD\n - script: git branch -r\nRun Code Online (Sandbox Code Playgroud)\n\n结果为job B:
来自 bitbucket.org\xef\xbc\x9a 的提交 ID
\n\n\n\n希望这可以帮助。
\n