0

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

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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'
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.