简体   繁体   English

Azure DevOps 从管道发送参数到 powershell

[英]Azure DevOps send parameters from pipeline to powershell

I tried to find some information in inte.net.我试图在 inte.net 中找到一些信息。 But unfortunately I could not found any information.但不幸的是我找不到任何信息。 Im trying to send pipeline parameters from pipeline into powershell script我试图将管道参数从管道发送到 powershell 脚本

pipeline below:下面的管道:

parameters:
    - name: env
      displayName: Select Environment
      type: string
      default: development
    
stages:
- stage: test
  displayName: test var
  jobs:
  - job: PostgresSQL
    steps:
      - task: PowerShell@2
        inputs:
          filePath: '$(5ystem. DefaultWorkingDirectory)/test.psl'
          errorActionPreference: 'continue'
        enabled: true

I need to send ${{ parameters.env }} to powershell. I tried different type of define param like a variable into powershell. but it does not work.我需要将${{ parameters.env }}发送到 powershell。我尝试了不同类型的定义参数,例如将变量发送到 powershell。但它不起作用。

I would be very happy if anybody can help me and share relevant documentation for that.如果有人可以帮助我并为此分享相关文档,我将非常高兴。

Thanks all谢谢大家

First approach is to provide arguments using 'arguments' keyword (available in PowerShell by 'param')第一种方法是使用“arguments”关键字提供 arguments(通过“param”在 PowerShell 中可用)

filePath: xyz
arguments: -input1 ${{ parameters.env }}

documentation and example - https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/powershell-v2?view=azure-pipelines#call-powershell-script-with-multiple-arguments文档和示例 - https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/powershell-v2?view=azure-pipelines#call-powershell-script-with-multiple-arguments

Second approach you can map parameters to environment variables provided to script using 'env' keyword第二种方法,您可以将 map 参数传递给使用“env”关键字提供给脚本的环境变量

env:
  input1: ${{ parameters.env }}

documentation - https://learn.microsoft.com/en-us/azure/devops/pipelines/process/tasks?view=azure-devops&tabs=yaml#environment-variables文档 - https://learn.microsoft.com/en-us/azure/devops/pipelines/process/tasks?view=azure-devops&tabs=yaml#environment-variables

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Azure DevOps管道中从PowerShell运行Terraform - Running Terraform from PowerShell in an Azure DevOps Pipeline Azure devOps管道中的Powershell脚本 - Powershell script in azure devOps pipeline Azure Devops 管道构建参数 - Azure Devops Pipeline Build Parameters 从 Azure DevOps 管道启动 Developer PowerShell for VS 2019 - Start Developer PowerShell for VS 2019 from Azure DevOps pipeline Powershell 从 azure devops build pipeline 获取组件治理结果 - Powershell to fetch the Component Governance result from azure devops build pipeline 在 Azure DevOps 管道中运行 Azure powershell 命令 - Run Azure powershell commands in Azure devops pipeline 如何将 Powershell 脚本文件路径从 azure devops repo 传递到 Azure devops 构建管道 - how to pass Powershell script filepath from azure devops repo into Azure devops build pipeline Azure DevOps:如何从 Release Pipeline 中的 PowerShell 脚本构建 Azure Pipeline 检索构建工件? - Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline? 在 Azure DevOps 管道中的 PowerShell 中使用参数 - Use parameter in PowerShell in Azure DevOps pipeline Azure Devops powershell 发布管道奇怪的字符 - Azure Devops powershell release pipeline strange chars
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM