目前我们有两个存储库,一个用于基础设施相关,一个用于源代码。当我想根据 Infra 分支计算它的计算时,因为那是它实际运行的地方。如何计算不同存储库中源代码分支的 git 版本并应用?我正在使用 Azure 管道。目前它在 Infra 分支工作
计算标签
- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: '5.x'
- task: gitversion/execute@0
displayName: Determine Version
inputs:
useConfigFile: true
configFilePath: 'global/GitVersion.yml'
应用标签
- task: Bash@3
inputs:
targetType: 'inline'
script: |
git config --global user.email "$(Build.RequestedForEmail)"
git config --global user.name "$(Build.RequestedFor)"
if [ $(git tag -l "$(GitVersion.SemVer)") ]; then
echo "Tag $(GitVersion.SemVer) already exists. Skipping Tagging."
else
git tag $(GitVersion.SemVer) -m "release build"
git push origin $(GitVersion.SemVer) --force
fi
更新*
基于这个githttps://github.com/GitTools/actions/issues/172我可以看到我们可以设置目标分支,当我设置时我收到警告并且它选择dev作为默认值。
已找到多个源分支,选择第一个(dev)。 这可能会导致提交计数不正确。 选项有: 开发,发布/1.0.1,发布/1.0.2,发布/1.0.0,主
根据您的期望和更新,您可以使用下面的示例进行测试。
Infra
存储库的
Infra
分支中的azure-pipelines.yml 文件 (
self
/Repo1
)trigger:
- Infra
pool:
vmImage: ubuntu-latest
resources:
repositories:
- repository: Repo2
name: SourceCode
type: git
steps:
- checkout: self
path: s/Repo1
fetchDepth: 0
persistCredentials: true
- checkout: Repo2
path: s/Repo2
fetchDepth: 0
- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: '5.x'
- task: gitversion/execute@0
displayName: Determine Version
inputs:
targetPath: '$(Agent.BuildDirectory)/s/Repo1'
useConfigFile: true
configFilePath: '$(Agent.BuildDirectory)/s/Repo1/global/GitVersion.yml'
- task: Bash@3
inputs:
targetType: 'inline'
script: |
echo "========== Show file structure in Agent.BuildDirectory =========="
tree $(Agent.BuildDirectory)
echo "GitVersion.SemVer is $(GitVersion.SemVer)"
git config --global user.email "$(Build.RequestedForEmail)"
git config --global user.name "$(Build.RequestedFor)"
if [ $(git tag -l "$(GitVersion.SemVer)") ]; then
echo "Tag $(GitVersion.SemVer) already exists. Skipping Tagging."
else
git tag $(GitVersion.SemVer) -m "release build"
git push origin $(GitVersion.SemVer) --force
fi
workingDirectory: '$(Agent.BuildDirectory)/s/Repo1/'
此管道首先将
self
存储库 (Infra
) 检出到与 s/Repo1
相关的 $(Agent.BuildDirectory)
文件夹中;然后,类似地,它将 Repo2
(SourceCode
) 检出到 s/Repo2
文件夹中;请参阅结账路径;
由于期望是从 Infra 存储库标记
Infra
分支,因此管道然后使用 中的
gitverion
执行
cofigFile
$(Agent.BuildDirectory)/s/Repo1/global/GitVersion.yml
并且 targetPaht 为 $(Agent.BuildDirectory)/s/Repo1
;此路径是签出 Infra
存储库的位置。
然后在 git 命令的帮助下,管道标记
infra
与 $(GitVersion.SemVer)
。