[英]using team city to insert build number & perform string replacement operations
I am using team city 9.1.7
version on Windows 2012 server. 我在Windows 2012服务器上使用
team city 9.1.7
版本。 As part of the build steps, I build a nodejs based application using command line. 作为构建步骤的一部分,我使用命令行构建基于nodejs的应用程序。 The output is bunch of Javascript and html files.
输出是一堆Javascript和html文件。
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 找到这个
<script src="bundle.js"></script>
和
replace with <script src="bundle.js?time=getTime()"></script>
替换为
<script src="bundle.js?time=getTime()"></script>
will results in <script src="bundle.js?time=4324324324"></script>
将导致
<script src="bundle.js?time=4324324324"></script>
Try the following 请尝试以下方法
Add a PowerShell step and run the following as source code 添加PowerShell步骤并将以下内容作为源代码运行
$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 catch块中
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.