powershellazure-devopsazure-pipelinesazure-pipelines-yaml

powershell: Getting path error while replacing json file


In one of the job i am replacing tenants Json file. So it needs to provide the tenants json exact path also the tenants json has been provided in one of the variable. I know the exact path for the tenants json file but i am getting the following error.

##[error]Invalid file path 'C:__w\1\s'. A path to a .ps1 file is required.

Also the yaml code looks like,

- task: PowerShell@2
  displayName: Override Tenants.json file
  inputs:
    scriptType: inlineScript
    inlineScript: >-
      $json = @'
      $(Deployment.tenantContent)
      '@;
      $json | Out-File -encoding "UTF8" "$(Deployment.FilePath)"

My exact path for the TenantsJsonPath = C:\__w\1\s\bapiweb-PowerBI\code\powerbi\PowerBi.Web\App_Data\tenants.json

The variable is assigned FilePath = web-PBI\code\pobi\PoBi.Web\App_Data\tenants.json

Could you please help me to resolve this issue, i am trying very hard but nothing helps me.


Solution

  • I can reproduce the same issue when using the same PowerShell Task definition.

    enter image description here

    The cause of the issue is that the syntax of the PowerShell task has issue.

    To solve this issue, you can use the following PowerShell task sample:

    - task: PowerShell@2
      displayName: Override Tenants.json file
      inputs:
        targetType: 'inline'
        script: |
          $json = @'
            $(Deployment.tenantContent)
          '@;
          $json | Out-File -encoding "UTF8" "$(Deployment.FilePath)"
    

    For more detailed info, you can refer to this doc: PowerShell@2 - PowerShell v2 task