问题描述
是否可以在阶段中从特定的哈希引用仓库? 例如:作为参数,我提供了提交的哈希值,并且由于有了这个参数,我可以在阶段'build'中使用特定版本的存储库中的repo文件夹。
解决方法
同意Krzysztof Madej。
在天蓝色的devop中,没有现成的方法可以通过Commit Sha指定特定版本的仓库。
但是您可以通过git命令来实现。
由于您已经拥有提交sha,因此可以在命令行任务中运行git reset --hard
。然后,源存储库将回滚到相应的版本。
这里是示例:
cd $(build.sourcesdirectory)
git reset --hard $commithash
经典管道
Yaml管道:
steps:
- task: CmdLine@2
inputs:
script: |
cd $(build.sourcesdirectory)
git reset --hard Commitsha
在天青管道,默认结帐步骤相当于git的克隆,它将包含提交历史,所以可以直接使用git commad回滚回购版本,而无需禁用(- checkout: none
)结帐步骤。这样会更方便
没有,出于两个原因,无法使用现成的工具来做到这一点。
一个资源库不允许传递特定的提交:
resources:
repositories:
- repository: string # identifier (A-Z,a-z,0-9,and underscore)
type: enum # see the following "Type" topic
name: string # repository name (format depends on `type`)
ref: string # ref name to use; defaults to 'refs/heads/master'
endpoint: string # name of the service connection to use (for types that aren't Azure Repos)
trigger: # CI trigger for this repository,no CI trigger if skipped (only works for Azure Repos)
branches:
include: [ string ] # branch names which will trigger a build
exclude: [ string ] # branch names which will not
tags:
include: [ string ] # tag names which will trigger a build
exclude: [ string ] # tag names which will not
paths:
include: [ string ] # file paths which must match to trigger a build
exclude: [ string ] # file paths which will not trigger a build
,第二个您目前不能在资源范围内使用模板语法。使用运行时参数是模板表达式的一个示例。
因此,您应该设置
- checkout: none
阻止获取源代码,然后使用命令行自行处理。这样,您应该能够使用运行时参数执行此操作(并将您的commit sha作为参数传递)。
您可以签出here