how to retrieve the path to workspace_publish branch OR any branch in devops , use that path in azure powershell script to read file from that branch.

Wasim 20 Reputation points
2024-05-15T12:58:55.19+00:00

I want to retrieve path to the branch and folder inside it, basically i wan to read the jsons here and change the dev keyword with uat and save the file back to the sam folder in workspace_publish branch. I can change dev to uat, but am not able to correctly use the path to the files. I am doing this in powershell task in release pipeline.

I have tried using this path :

$(System.DefaultWorkingDirectory)_Data Stage V9_u\foldername\TemplateForWorkspace.json

User's image

But i am getting path error with this.

i have tried changig slashes / \ too but the error persists.

User's image

User's image

024-05-15T07:05:41.1203526Z ##[section]Starting: PowerShell Script
2024-05-15T07:05:41.1616420Z ==============================================================================
2024-05-15T07:05:41.1616789Z Task         : PowerShell
2024-05-15T07:05:41.1616958Z Description  : Run a PowerShell script on Linux, macOS, or Windows
2024-05-15T07:05:41.1617027Z Version      : 2.237.5
2024-05-15T07:05:41.1617162Z Author       : Microsoft Corporation
2024-05-15T07:05:41.1617303Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2024-05-15T07:05:41.1617380Z ==============================================================================
2024-05-15T07:05:42.6804168Z Generating script.
2024-05-15T07:05:42.7117125Z ========================== Starting Command Output ===========================
2024-05-15T07:05:42.7368835Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\agent\_work\_temp\bc7b551c-5267-4e4c-9e52-e2a0683185c5.ps1'"
2024-05-15T07:05:43.1695349Z At C:\agent\_work\_temp\bc7b551c-5267-4e4c-9e52-e2a0683185c5.ps1:6 char:48
2024-05-15T07:05:43.1696665Z + $inputPath = $(System_DefaultWorkingDirectory)/_Data Lake V1_u/synw-i ...
2024-05-15T07:05:43.1697533Z +                                                ~
2024-05-15T07:05:43.1698046Z You must provide a value expression following the '/' operator.
2024-05-15T07:05:43.1698617Z At C:\agent\_work\_temp\bc7b551c-5267-4e4c-9e52-e2a0683185c5.ps1:6 char:48
2024-05-15T07:05:43.1698943Z + $inputPath = $(System_DefaultWorkingDirectory)/_Data Lake V1_u/synw-i ...
2024-05-15T07:05:43.1699371Z +                                                ~~~~~
2024-05-15T07:05:43.1699808Z Unexpected token '_Data' in expression or statement.
2024-05-15T07:05:43.1700391Z At C:\agent\_work\_temp\bc7b551c-5267-4e4c-9e52-e2a0683185c5.ps1:8 char:49
2024-05-15T07:05:43.1700678Z + $outputPath = $(System_DefaultWorkingDirectory)/_Data Lake V1_u/synw- ...
2024-05-15T07:05:43.1701093Z +                                                 ~
2024-05-15T07:05:43.1701527Z You must provide a value expression following the '/' operator.
2024-05-15T07:05:43.1702120Z At C:\agent\_work\_temp\bc7b551c-5267-4e4c-9e52-e2a0683185c5.ps1:8 char:49
2024-05-15T07:05:43.1702404Z + $outputPath = $(System_DefaultWorkingDirectory)/_Data Lake V1_u/synw- ...
2024-05-15T07:05:43.1702797Z +                                                 ~~~~~
2024-05-15T07:05:43.1703199Z Unexpected token '_Data' in expression or statement.
2024-05-15T07:05:43.1703584Z     + CategoryInfo          : ParserError: (:) [], ParseException
2024-05-15T07:05:43.1704538Z     + FullyQualifiedErrorId : ExpectedValueExpression
2024-05-15T07:05:43.1704685Z  
2024-05-15T07:05:43.3041139Z ##[error]PowerShell exited with code '1'.
2024-05-15T07:05:43.4458601Z ##[section]Finishing: PowerShell Script

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,504 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,805 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,186 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ShaikMaheer-MSFT 38,291 Reputation points Microsoft Employee
    2024-05-16T16:26:35.4466667+00:00

    Hi Wasim,

    Thank you for posting query in Microsoft Q&A Platform.

    You can make API call to update folders i guess. Below is the link to API documentation.
    https://learn.microsoft.com/en-us/rest/api/azure/devops/build/folders/update?view=azure-devops-rest-7.1

    Consider exploring API call, option.

    Hope this helps.