Azure devops 是否可以在YAML模板中导入脚本

Azure devops 是否可以在YAML模板中导入脚本,azure-devops,Azure Devops,我有一个名为devops的Azure回购协议 我的管道中声明了一个名为devops 参考模板工程: - template: templates/template.yaml@devops 在devops/templates/template.yaml文件中,我想添加一个步骤来执行驻留在devops/scripts/myscript.ps1中的powershell脚本 这可能吗? template.yaml文件中的语法是什么 我试过这个,但不起作用: steps: - task: Power

我有一个名为devops的Azure回购协议 我的管道中声明了一个名为
devops

参考模板工程:

 - template: templates/template.yaml@devops
devops/templates/template.yaml
文件中,我想添加一个步骤来执行驻留在
devops/scripts/myscript.ps1中的powershell脚本

这可能吗?
template.yaml
文件中的语法是什么

我试过这个,但不起作用:

steps:
  - task: PowerShell@2
    inputs:
      filePath: scripts/myscript.ps1@devops
请试试这个:

#templates/template.yaml
参数:
-名称:repo#未指定参数的默认值
默认值:“”
步骤:
-任务:PowerShell@2
投入:
文件路径:${parameters.repo}}/scripts/myscript.ps1
和构建定义:

资源:
存储库:
-存储库:devops
类型:github
名称:kmadof/devops模板
端点:kmadof
步骤:
-结帐:self
-结帐:devops
-模板:模板/模板。yaml@devops
参数:
repo:devops模板
如果您删除了
checkout:self
,您将直接在
(Agent.BuildDirectory)
中获得它们的内容
devops
repo。请查看更多信息。

请尝试以下操作:

#templates/template.yaml
参数:
-名称:repo#未指定参数的默认值
默认值:“”
步骤:
-任务:PowerShell@2
投入:
文件路径:${parameters.repo}}/scripts/myscript.ps1
和构建定义:

资源:
存储库:
-存储库:devops
类型:github
名称:kmadof/devops模板
端点:kmadof
步骤:
-结帐:self
-结帐:devops
-模板:模板/模板。yaml@devops
参数:
repo:devops模板

如果您删除了
checkout:self
,您将直接在
(Agent.BuildDirectory)
中获得它们的内容
devops
repo。请查看更多信息。

假设这两个回购协议在同一个团队项目中。然后:

devops
repo中的
template.yaml
应为:

steps:
  - task: PowerShell@2
    inputs:
      filePath: scripts/myscript.ps1
resources:
  repositories:
    - repository: devops
      type: git
      name: ProjectName/devops

steps:
- checkout: devops
- template: template.yaml@devops
main
repo中的构建定义应为:

steps:
  - task: PowerShell@2
    inputs:
      filePath: scripts/myscript.ps1
resources:
  repositories:
    - repository: devops
      type: git
      name: ProjectName/devops

steps:
- checkout: devops
- template: template.yaml@devops

由于
-checkout:devops
只下载repos的内容,
scripts/myscript.ps1
就足够了,我们不需要
scripts/myscript。ps1@devops
。您的问题的直接原因是Azure Devops服务不会自动将online
Devops
repo的内容下载到本地代理。只要确保devops的内容是下载的,一切都会好起来的

假设这两个回购协议在同一个团队项目中。然后:

devops
repo中的
template.yaml
应为:

steps:
  - task: PowerShell@2
    inputs:
      filePath: scripts/myscript.ps1
resources:
  repositories:
    - repository: devops
      type: git
      name: ProjectName/devops

steps:
- checkout: devops
- template: template.yaml@devops
main
repo中的构建定义应为:

steps:
  - task: PowerShell@2
    inputs:
      filePath: scripts/myscript.ps1
resources:
  repositories:
    - repository: devops
      type: git
      name: ProjectName/devops

steps:
- checkout: devops
- template: template.yaml@devops
由于
-checkout:devops
只下载repos的内容,
scripts/myscript.ps1
就足够了,我们不需要
scripts/myscript。ps1@devops
。您的问题的直接原因是Azure Devops服务不会自动将online
Devops
repo的内容下载到本地代理。只要确保devops的内容是下载的,一切都会好起来的