Azure devops 停止azure管道运行我的模板文件
我正在尝试使用Azure管道模板来组织我的构建。 我正在为此使用多个存储库:Azure devops 停止azure管道运行我的模板文件,azure-devops,azure-pipelines,Azure Devops,Azure Pipelines,我正在尝试使用Azure管道模板来组织我的构建。 我正在为此使用多个存储库: 构建模板 MySoftwareProject 1 MySoftwareProject 2 MySoftwareProjectN BuildTemplates repo包含所有模板,我想从其他repo中使用这些模板。 我试图确保,当BuildTemplates repo被更改时,没有一条管道被触发运行(这些是模板,不应该运行),稍后将对此进行详细介绍。 文件夹结构如下所示: 我还将这些模板作为管道添加到Azure(
- 构建模板
- MySoftwareProject 1
- MySoftwareProject 2
- MySoftwareProjectN
trigger:none
,它在导入作业时有效,但在导入步骤时无效。
以下是构成此构建的所有yaml文件:
触发器:
-主人
游泳池:
vmImage:“windows最新版本”
资源:
存储库:
-存储库:构建模板
类型:git
名称:HMI/BuildTemplates
延伸:
模板:NuGet/Jobs/NuGet.Build。yml@BuildTemplates
#不要运行模板注意:这很有效!
触发器:无
参数:
-名称:packagesToPack
类型:字符串
默认值:'***.nuspec'
工作:
-工作:包装
步骤:
-模板:../Steps/NuGet.Build.yml
参数:
packagesToPack:${{parameters.packagesToPack}
#不要运行模板注意:这不起作用!
#触发器:无
步骤:
-任务:NuGetToolInstaller@1
-任务:NuGetCommand@2
投入:
命令:“打包”
packagesToPack:${{parameters.packagesToPack}
版本方案:“byPrereleaseNumber”
主要版本:“7”
minorVersion:'1'
修补程序版本:“0”
-任务:PublishBuildArtifacts@1
投入:
PathtoPublish:“$(Build.ArtifactStagingDirectory)”
工件名称:“文件”
publishLocation:“容器”
当我从/steps/NuGet.Build.yml
文件中取消注释#trigger:none
时,在尝试运行构建(使用第一个提到的yaml文件)时会发生以下情况
/NuGet/Steps/NuGet.Build。yml@BuildTemplates(第3行,第1列):意外值“触发器”
因此,我的问题是:当我将模板定义为管道时,如何停止模板自动运行,以便使用管道编辑器?
我可以禁止管道在某处运行吗?
我是否可以有条件地添加“触发器:无”
我还考虑创建一个trigger none.yml
文件,其内容仅为trigger:none
,并使用extend来选择性地包含它或其他内容,但我认为这不起作用
是否有其他方法可以使用工具支持编辑模板?例如是否有vscode扩展名或其他内容?不幸的是,如果文件只包含步骤,则没有真正的方法将yaml文件添加到管道并停止其运行。这将导致yaml编译错误 因此,似乎没有办法获得yaml模板的在线编辑器 下一个最好的东西是可怕的弗罗斯特提出的,VSCode扩展 我已添加powershell脚本以自动更新架构定义:
# This powershell updates the Yaml schema file.
Set-StrictMode -Version Latest
# Configure these options before running
#
# The personal access token to use.
# Grant the Token Administration(Read & manage) or Tokens(Read & manage) permission to the PAT.
# Also see: https://stackoverflow.com/a/64868268/4122889
$pat = 'TODO'
# Name of the organization
$organizationName = "TODO"
$yamlSchemaPartUrl = "https://dev.azure.com/{0}/_apis/distributedtask/yamlschema?api-version=6.0" # &accessToken={1}
$yamlSchemaUrl = $yamlSchemaPartUrl -f $organizationName #, $pat
$outputFile = ".\yamlschema.json"
Write-Host "Going to fetch file at " $yamlSchemaUrl " to: " $(Resolve-Path -Path $outputFile)
# See the resources below for how authentication with the PAT works:
# https://tenbulls.co.uk/2020/03/11/querying-azure-devops-rest-api-with-powershell/
# https://docs.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-6.1#assemble-the-request
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($pat)"))
$props = @{
Uri = $yamlSchemaUrl
Method = 'GET'
ContentType = 'application/json'
Headers = @{authorization = "Basic $token"}
}
# Write-Host $props.Headers.accessToken
Invoke-RestMethod @props -OutFile $outputFile
# Invoke-WebRequest $yamlSchemaUrl -OutFile $outputFile
Write-Host "Done, please restart VsCode to apply the changes."
Write-Warning "Make sure the output file is correct - if it is a bunch of html, something likely went wrong with the PAT"
Write-Host "if thats the case download the yaml schema manually via the browser, or fix the PAT"
不过,我还是会将项目复制并粘贴到在线编辑器中。不要认为模板应该是管道。模板将插入到现有管道中。知道这不是你要问的,但觉得这是一个相当大的转移,从什么将被视为最佳实践。考虑在一个新的分支中对模板回购进行更改,并选择Realth-> YAML TAMPLALLE-> BanCH版本来测试新的变化。我明白你的意思,我真的很想在编辑yaml时使用工具,但这是我将它们作为管道添加的唯一原因。你能澄清一下你对
Resources->YAML Templatel->banch version
的意思吗?因为我不太明白。模板应该是一个存储库资源,而不是一个管道,如果你想创建严肃的管道,不要挂断使用web UI。我建议使用vscode+azure管道扩展(使用intellisense)。我有一大堆模板,以防您需要最佳实践的灵感,这些模板在这里@alv hi alv使用,谢谢您的时间。我知道这不是正常的做法,但是我想使用azure管道提供的工具,在这里我只需按任务的设置,就可以获得有关该任务的所有信息。我还不知道vscode扩展,谢谢你,尽管很遗憾,它也没有提供前面提到的功能。还感谢您的示例repo's-我将在周一查看。@如果您想这样做,只需点击UI中的YAML按钮,即可复制YAML并插入管道。可能需要按摩一下,但这是一个好的开始。