gpt4 book ai didi

Powershell 构建步骤,一劳永逸?

转载 作者:行者123 更新时间:2023-12-03 00:34:11 27 4
gpt4 key购买 nike

我正在使用 TFS 2018 在构建步骤中运行以下 powershell 命令。

Start-Job -ScriptBlock {
Invoke-Command -FilePath \\MyServer\run.ps1 -ComputerName MyServer -ArgumentList arg1, arg2
}

由于我不希望脚本影响构建步骤,因此应该简单地触发并忘记脚本。因此我使用 Start-Job。但似乎一旦该步骤完成,该进程就会被终止。即使构建步骤已完成或构建过程已完成,是否有办法维持进程生命周期?

其他信息...powershell 脚本应在远程服务器上运行。该脚本本身会触发带有参数的 .exe。

最佳答案

要简单地一劳永逸,请使用 Invoke-Command -AsJob 调用脚本:

Invoke-Command -AsJob -FilePath \\MyServer\run.ps1 -ComputerName MyServer -Args arg1, arg2
Start-Sleep 1 # !! Seemingly, this is necessary, as @doorman has discovered.
  • 这应该远程异步启动脚本,并在本地 session 中创建一个作业来监视其执行情况。

    • 警告:使用Start-Sleep - 可能需要更长的等待时间 -为了在调用脚本退出之前创建远程进程,这似乎是必要的,但这样的解决方案可能不完全可靠,因为没有保证时间。
  • 由于您不打算监视远程执行,因此本地 session 终止 - 以及随之而来的监视作业 - 应该不重要。

关于Powershell 构建步骤,一劳永逸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49017321/

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