SSH to a server from Jenkins and run shell commands SSH to a server from Jenkins and run shell commands unix unix

SSH to a server from Jenkins and run shell commands


Hey @ Siraj Syed check following example:

String commandToRun = 'cat /home/ec2-user/testfile.txt; rm -rf /home/ec2-user/testfile.txt'// pipeline stepsh "ssh -o StrictHostKeyChecking=no -i /home/ec2-user/card.pem ec2-user@10.205.75.204 /bin/bash -c '\"${commandToRun}\"'"


Can you just do:

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"