从Jenkins管道发送VM命令

时间:2020-08-24 14:53:53

标签: azure powershell jenkins window azure-cli

我正在构建一个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>

可以通过什么方式使脚本起作用?

1 个答案:

答案 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\\"
    '''