Git 在Azure中,我可以在使用多个回购触发器时动态签出回购吗?
我使用的是Azure git,我的管道使用的是多重回购触发器 我想签出触发构建的回购协议。我看到Git 在Azure中,我可以在使用多个回购触发器时动态签出回购吗?,git,repository,azure-pipelines,pipeline,git-checkout,Git,Repository,Azure Pipelines,Pipeline,Git Checkout,我使用的是Azure git,我的管道使用的是多重回购触发器 我想签出触发构建的回购协议。我看到checkout:self使用了.yml文件所在的存储库,而不是触发构建的存储库 我发现$(Build.Repository.Name)包含触发生成的repo的名称 因此,在我的.yml文件中,我试图将其传递到签出步骤,但出现错误: resources: repositories: - repository: A type: git name: Dev/A trigge
checkout:self
使用了.yml文件所在的存储库,而不是触发构建的存储库
我发现$(Build.Repository.Name)
包含触发生成的repo的名称
因此,在我的.yml文件中,我试图将其传递到签出步骤,但出现错误:
resources:
repositories:
- repository: A
type: git
name: Dev/A
trigger:
- '*'
- repository: B
type: git
name: Dev/B
trigger:
- '*'
- repository: C
type: git
name: Dev/C
trigger:
- '*'
pool: Default
steps:
- checkout: git://Dev/$(Build.Repository.Name)@refs/heads/master
- checkout: git://Dev/B@refs/heads/master
错误消息是:
The pipeline is not valid. The repository $(Build.Repository.Name) in project Dev could not be retrieved. Verify the name and credentials being used.
如何将变量传递到签出步骤?预定义变量Build.Repository.Name
是触发存储库的名称,而不是触发生成的回购协议的名称。有关详细信息,请参阅
此外,通过引用此文档:,签出
步骤在对此生成进行排队时得到验证,恐怕您无法使用更改其引用存储库名称,这可能会在运行时为脚本和任务设置不同的值
因此,作为一种解决方法,您可以使用预定义变量Build.TriggeredBy.ProjectID
获取包含触发生成的项目的ID。并使用uild.TriggeredBy.DefinitionId
获取触发生成的定义ID
然后使用RESTAPI:从响应中获取触发内置repository.url的存储库。其格式类似于https://dev.azure.com/{organization}/{project}/{u git/{repository name}
最后,您可以使用命令gitclone添加一个签出库https://username:PAT@dev.azure.com/{organization}/{project}/{u git/{repository name}
,您可以生成一个。你好,我的答案有用吗?如果是,你可以接受它作为一个答案,它可以帮助其他社区成员谁得到同样的问题,感谢你的反馈。