简体   繁体   中英

Azure DevOps send parameters from pipeline to powershell

I tried to find some information in inte.net. But unfortunately I could not found any information. Im trying to send pipeline parameters from pipeline into powershell script

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.

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')

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

Second approach you can map parameters to environment variables provided to script using 'env' keyword

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM