So I am trying to use the below script do dynamically put different values in a properties file But powershell will not let me use special characters such as !
@echo off
setlocal enabledelayedexpansion
rem Set the properties file path
set "PROPERTIES_FILE=src\main\resources\config.properties"
rem Replace placeholders with Jenkins parameters in the properties file
powershell -Command "(Get-Content '%PROPERTIES_FILE%') | ForEach-Object { $_ -replace 'USERNAME=(.*)', 'USERNAME=%Username%' } | Set-Content '%PROPERTIES_FILE%'"
powershell -Command "(Get-Content '%PROPERTIES_FILE%') | ForEach-Object { $_ -replace 'PASSWORD=(.*)', ('PASSWORD=' + [regex]::escape('%Password%')) } | Set-Content '%PROPERTIES_FILE%'"
rem Optionally, print the updated file contents for verification
type "%PROPERTIES_FILE%"
rem Execute your Maven command
mvn clean test -Dtest=ScriptTest
I am trying to use Jenkins parameters to update a config.properties file.