gpt4 book ai didi

jetbrains-ide - 使用团队城市插入内部版本号并执行字符串替换操作

转载 作者:行者123 更新时间:2023-12-01 08:52:15 25 4
gpt4 key购买 nike

我正在使用 team city 9.1.7 Windows 2012 服务器上的版本。作为构建步骤的一部分,我使用命令行构建了一个基于 nodejs 的应用程序。输出是一堆 Javascript 和 html 文件。

在下一步中(在构建结束并生成输出之后),我想执行以下操作:

  • 从团队城市获取当前版本号并将其插入到 index.html(在输出文件夹中可用)文件中。我想添加一个可以告诉我构建版本的元标记。
  • 在同一个文件(index.html)中,我想执行字符串查找和替换操作。我想为文件添加时间戳。

  • 找到这个 <script src="bundle.js"></script>

    替换为 <script src="bundle.js?time=getTime()"></script>
    将导致 <script src="bundle.js?time=4324324324"></script>

    最佳答案

    尝试以下

    添加一个 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

    这将读取文件内容并对它们执行两次替换,然后写回文件。

    ![enter image description here

    不确定您的文件路径是什么或您想要调用的标题是什么,但您应该能够更改它以满足您的要求。

    希望这可以帮助

    修订

    要捕获任何异常,请尝试将代码包装在 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
    }

    要打破缓存,您可以使用版本号,因为这将增加每个构建,因此是唯一的
    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
    }

    关于jetbrains-ide - 使用团队城市插入内部版本号并执行字符串替换操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38599086/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com