Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 从Jenkins到服务器的SSH并运行shell命令_Unix_Amazon Web Services_Jenkins_Jenkins Pipeline - Fatal编程技术网

Unix 从Jenkins到服务器的SSH并运行shell命令

Unix 从Jenkins到服务器的SSH并运行shell命令,unix,amazon-web-services,jenkins,jenkins-pipeline,Unix,Amazon Web Services,Jenkins,Jenkins Pipeline,全部, 我试图通过Jenkins在远程服务器上运行多个shell命令 我已经用executeshell插件尝试了下面的代码 sudo su 问题是我只能运行一个命令,需要运行的命令超过1个 sudo su 我们如何实现这样的多命令运行?您能做到: ssh -o StrictHostKeyChecking=no -i /home/ec2-user/card.pem ec2-user@10.205.75.204 "cat /home/ec2-user/testfile.txt; rm -rf /ho

全部,

我试图通过Jenkins在远程服务器上运行多个shell命令

我已经用executeshell插件尝试了下面的代码 sudo su

问题是我只能运行一个命令,需要运行的命令超过1个 sudo su

我们如何实现这样的多命令运行?

您能做到:

ssh -o StrictHostKeyChecking=no -i /home/ec2-user/card.pem ec2-user@10.205.75.204 "cat /home/ec2-user/testfile.txt; rm -rf /home/ec2-user/testfile.txt"

Hey@Siraj Syed检查以下示例:

String commandToRun = 'cat /home/ec2-user/testfile.txt; rm -rf /home/ec2-user/testfile.txt'

// pipeline step
sh "ssh -o StrictHostKeyChecking=no -i /home/ec2-user/card.pem ec2-user@10.205.75.204 /bin/bash -c '\"${commandToRun}\"'"

我担心它对管道@Peter McNab不起作用,第二个命令将在jenkins上运行,而不是在远程主机上运行。
ssh -o StrictHostKeyChecking=no -i /home/ec2-user/card.pem ec2-user@10.205.75.204 "cat /home/ec2-user/testfile.txt; rm -rf /home/ec2-user/testfile.txt"
String commandToRun = 'cat /home/ec2-user/testfile.txt; rm -rf /home/ec2-user/testfile.txt'

// pipeline step
sh "ssh -o StrictHostKeyChecking=no -i /home/ec2-user/card.pem ec2-user@10.205.75.204 /bin/bash -c '\"${commandToRun}\"'"