Lucky
Lucky

Reputation: 303

Yaml parameter to inline script

Hello I think the problem I am facing might be a beginner doubt, but here it is:

I have a stage yaml which is called by my main yaml. Stage yaml has a parameter which I want to use in inline script.

Here is the yaml (skeleton)

parameters:
- name: myParam
  type: string

stages:
- stage: 
  dependsOn:   
  displayName: 
  pool:
    name: 
  jobs:
  - deployment: 
    displayName: 
    pool:
      name: 
    environment: 
      name: 
    strategy:
      runOnce:
        deploy:
          steps:
          - template: 
            parameters:
              azureServiceConnection: 
              subscriptionId: 

          - task: AzureCLI@2
            displayName: ''              
            inputs:
              workingDirectory: ''
              azureSubscription: 
              scriptType: 'pscore'
              scriptLocation: inlineScript
              inlineScript: |
                
                Write-Host  //I want to print it here or assign to a variable like next line
                $paramValue = //here
                

How can I use myParam here?

Upvotes: 1

Views: 2182

Answers (2)

atconway
atconway

Reputation: 21314

Here is an example with the correct syntax for accessing your parameter's value in your .yml file:

parameters:
- name: myParam
  type: string
  ...
       scriptType: 'pscore'
       scriptLocation: inlineScript
       inlineScript: |
          Write-Host "Value of myParam is ${{ parameters.myParam }}"  
          $paramValue = "${{ parameters.myParam }}"

The key here is to use the syntax to access the value of that parameter in your .yml file $ {{ paramters.vaiableName }}

Upvotes: 1

Daniel Mann
Daniel Mann

Reputation: 59055

Specify an env block and reference the value as an environment variable.

i.e.

- task: AzureCLI@2
  inputs: 
    inlineScript: |
      Write-Host $env:FOO
  env:
    FOO: ${{ parameters.myParameter }}

Upvotes: 2

Related Questions