I am trying to execute a remote shell command using groovy script in jenkins console. Can you please let me know a proof of concept as how i can connect to the remote server and execute a shell command.
Thanks
I am trying to execute a remote shell command using groovy script in jenkins console. Can you please let me know a proof of concept as how i can connect to the remote server and execute a shell command.
Thanks
My goal is run a shell command where the file is located in remote linux server(does have a hostname,username and pwd). For this i was able to successfully execute it using the remote shell command by setting up the target linux server in Jenkins
Now , my requirement is to run the same script for a choice parameter in jenkins where i can execute using the groovy script. For this i am unable to figure out as how i can connect to remote linux server and execute the script below using groovy
while read -r line; do
if [[ "$(awk '{print $1}' <<<"$line")" == 'username' ]]; then
var_name="$(awk '{print $2}' <<<"$line" | awk -F'=' '{print $1}')"
var_value="$(awk -F\" '{print $2}' <<<"$line")"
echo -e "${var_name}"
else
continue
fi
done< /home/username/dir/targetfile.txt
I think we need a little more info about your 'remote server'. Is this currently setup as a Jenkins remote node? If so, it's pretty easy to execute a shell command on that remote node. For example, assuming you want to touch bar.txt on a remote agent named foo:
node('foo'){
sh 'touch bar.txt'
}