powershellazure-cli2azure-task-groups

How to set out put variable in Azure CLI task


I'm trying to write an Azure CLI task to use for further getting account keys and so on. First want to just have an output variable from the inline script but I got this error when build the pipeline:

"##[error]PowerShell exited with code '1'." "The term 'myOutputVar' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again." This is how I wrote it :

- task: AzureCLI@2
  displayName: Azure CLI
  inputs:
    azureSubscription: mySubscription
    scriptType: pscore
    scriptLocation: inlineScript
    inlineScript: |
      Write-Host "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value" 
      Write-Host "This is my output $(myOutputVar)"

Any idea on what I am doing wrong ? since I'm new to this, thanks


Solution

  • There is no problem with the first command that to set the output variable:

    Write-Host "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value"
    

    But the second command is not right. The variable is set as an output variable, so you can't output it inside the task. You can output the output variable in another task of the same stage.