简体   繁体   English

如何在Windows上通过SSH自动运行命令

[英]How to run a command over SSH automatically on Windows

I have two Windows boxes. 我有两个Windows盒子。 One is Jenkins build server. 一种是Jenkins构建服务器。 Second one is deployment box. 第二个是部署框。

I have installed SSH and created a user on the deployment Windows box. 我已经安装了SSH并在部署Windows框中创建了一个用户。 I can ssh to it from my Ubuntu workstation and run commands I need to run. 我可以在Ubuntu工作站上使用ssh并运行我需要运行的命令。

But I need to do this automatically from Jenkins. 但是我需要从詹金斯那里自动进行。 How to do it? 怎么做? Basically I need to make this automatic: 基本上,我需要使此自动化:

ssh richard@myserver
... enter password ...
cd C:/puppet && git pull
"/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin/puppet.bat" apply C:/puppet/manifests/site.pp

That's it. 而已。 Is there some way to do this from a batch file and just execute the *.bat file from Jenkins? 有什么方法可以从批处理文件执行此操作,而仅从Jenkins执行* .bat文件?

The publish over ssh plugin allows you to run remote commands. ssh上发布插件允许您运行远程命令。

In Manage Jenkins > Configure System > Publish over SSH you need to configure the remote machine you want to deploy to. 在“ 管理Jenkins” >“ 配置系统” >“ 通过SSH发布”中,您需要配置要部署到的远程计算机。 Click on Add and configure the connection to the server. 单击添加并配置与服务器的连接。

In the Job itself add a Build Step Send files or execute commands over SSH . 在作业本身中,添加构建步骤通过SSH发送文件或执行命令 Select from the drop down the SSH server you want to connect to. 从下拉列表中选择要连接的SSH服务器。 In the Exec command you can add all commands you want to have executed on the remote machine. Exec命令中 ,可以添加要在远程计算机上执行的所有命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM