我正在构建一个Jenkins管道,该管道应该允许我向Windows计算机发送远程命令。
例如,我想将文件从一个位置移动到另一个位置。我的管道代码如下所示:
az vm run-command invoke --command-id RunPowerShellScript --name VM_name -g test_g --scripts " Copy-Item -Path C:\BuildFiles\File.xml -Destination C:\Program Files (x86)\File\File Path\File version\"
在PowerShell中,它可以正常工作。但是,当我尝试从Jenkins作为蝙蝠脚本运行它(我在Windows上运行Jenkins)并添加语法bat''
或bat""
时,会出现语法错误或使脚本无效。 / p>
可以通过什么方式使脚本起作用?
答案 0 :(得分:0)
您不应该使用bat
函数,而应该使用powershell
函数。您的代码应如下所示。
powershell label: '', script: '''
az vm run-command invoke
--command-id RunPowerShellScript
--name VM_name
-g test_g
--scripts "
Copy-Item
-Path C:\\BuildFiles\\File.xml
-Destination C:\\Program Files (x86)\\File\\File Path\\File version\\"
'''