I am trying to connect ec2 instance 172.20.160.4 and create a testfolder, but it is connecting to its own instance. and the result is “Connected to ip-165-14-265-120.us-east-2.compute.internal”. And it creating testfolder on its own node.
agent {
label 'smg-mitger'
}
stage('Connect to EC2 and Perform Operations') {
steps {
script {
sh '''
#!/bin/bash
echo "Attempting to connect to EC2 instance"
ssh 172.20.160.4
echo "Connected to $(hostname)"
cd /home/ops
echo "Current directory:"
pwd
echo "Listing contents:"
ls -la
echo "Creating folder testfolder"
mkdir -p testfolder
echo "Folder created."
ls -la
'''
}
}
}