是否可以在YAML模板中导入脚本 [英] Is it possible to import a script in a YAML Template

查看:65
本文介绍了是否可以在YAML模板中导入脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 devops
的Azure存储库我的管道有一个声明为 devops
的资源引用模板的工作原理:

I have an Azure Repo called devops
My Pipeline has a resource declared called devops
Referencing to the template works:

 - template: templates/template.yaml@devops

我想在 devops/templates/template.yaml 文件中的

添加一个步骤,以执行驻留在 devops/scripts/myscript.ps1 中的powershell脚本

in the devops/templates/template.yaml file I would like to add a step that executes a powershell script that is residing in devops/scripts/myscript.ps1

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

Is this possible? What would the syntax be in the template.yaml file?

我尝试了此操作,但没有用:

I tried this, but it doesn't work:

steps:
  - task: PowerShell@2
    inputs:
      filePath: scripts/myscript.ps1@devops

推荐答案

请尝试以下操作:

#templates/template.yaml
parameters:
- name: repo  # defaults for any parameters that aren't specified
  default: ''

steps:
  - task: PowerShell@2
    inputs:
      filePath: ${{ parameters.repo }}/scripts/myscript.ps1

并建立定义:

resources:
  repositories:
    - repository: devops
      type: github
      name: kmadof/devops-templates
      endpoint: kmadof

steps:
- checkout: self
- checkout: devops
- template: templates/template.yaml@devops
  parameters:
    repo: devops-templates

如果您删除了 checkout:self ,您将直接在(Agent.BuildDirectory)中获得它们的内容 devops 回购.请看看

If you removed checkout: self you will get content of them devops repo directly in (Agent.BuildDirectory). Please take a look here for more info.

这篇关于是否可以在YAML模板中导入脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆