1

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?

Lucky
  • 81
  • 6

1 Answers1

1

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 }}
Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • If I add env in my task above (as shown in my question) I get an error A mapping was not expected – Lucky Jun 16 '23 at 05:37