Reputation: 19183
I am using team city 9.1.7
version on Windows 2012 server. As part of the build steps, I build a nodejs based application using command line. The output is bunch of Javascript and html files.
In the next step (after the build is over & output is generated), I want to perform following:
Find this <script src="bundle.js"></script>
and
replace with <script src="bundle.js?time=getTime()"></script>
will results in <script src="bundle.js?time=4324324324"></script>
Upvotes: 3
Views: 4538
Reputation: 3704
Try the following
Add a PowerShell step and run the following as source code
$versionNumber = "%build.number%"
$filePath = "%teamcity.agent.work.dir%\path\file.txt"
(GC $filePath).Replace("<head>", "<head><meta http-equiv='X-Version-Number' content='$versionNumber'>").Replace("bundle.js", "bundle.js?time=getTime()") | Set-Content $filePath
This will read the file contents in and perform two replacements on them and then write back to the file.
Not sure what your file path is or what you want the header called, but you should be able to change this to suit your requirements.
Hope this helps
To catch any exceptions, try wrapping the code in a try catch block
try {
(GC $filePath).Replace("<head>", "<head><meta http-equiv='X-Version-Number' content='$versionNumber'>").Replace("bundle.js", "bundle.js?time=getTime()") | Set-Content $filePath
}
catch [System.Exception] {
Write-Output $_
Exit 1
}
To break out of the cache you could use the version number as this will increment each build and thus be unique
try {
(GC $filePath).Replace("<head>", "<head><meta http-equiv='X-Version-Number' content='$versionNumber'>").Replace("bundle.js", "bundle.js?v=$versionNumber") | Set-Content $filePath
}
catch [System.Exception] {
Write-Output $_
Exit 1
}
Upvotes: 12