i am a newbie to DevOps, all i want to do is use a powershell pipeline to change a file content from DevOps.
my file content is :for example i want to change “Initial Catalog=databricks_connection” to “Initial Catalog=new_value”
this is the powershell script i created:
`param (
[string]$filePath,
[string]$searchString,
[string]$replaceString
)
$fileContent = Get-Content -Path $filePath -Raw
$newContent = $fileContent -replace [regex]::Escape($searchString), $replaceString
$newContent | Set-Content -Path $filePath
Write-Host “Content replaced successfully in file: $filePath”`
this is the yml pipeline:
`trigger: none
pool:
vmImage: ubuntu-latest
steps:
- task: PowerShell@2
displayName: ‘Replace File Content’
inputs:
targetType: ‘filePath’
filePath: ‘$(System.DefaultWorkingDirectory)/powershell.ps1’
arguments: ‘-filePath $(System.DefaultWorkingDirectory)/databricks_report.Report/definition.pbir -searchString “Initial Catalog=databricks_connection” -replaceString “Initial Catalog=new_value”‘`
whenever i run the pipeline it didn’t have any error and the pipeline is completed every time. but the target file isn’t got any updates at all. may i know is there any missing part from my script?
i just want my file content to be updated by the pipeline i called.
Keith chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.