Home Linux & Systems Cybersecurity Cloud & DevOps Networks & Infrastructure SIEM & Monitoring DFIR & Threat Intel Development & Other All categories Projects About Tools

Run script remotely with jenkins

Leer en espanol
Run script remotely with jenkins

Table of contents

Tutorial: https://red-orbita.com/?p=6622 This time we are going to create a simple job in which we will execute a script in ===

Previously we already talked about what Jenkins is, what it is for and we saw its installation.

Tutorial: https://red-orbita.com/?p=6622

This time we are going to create a simple job in which we will execute a script on a remote server using ssh.  To do this, the first thing we must configure is the RSA key so that it can connect without a password.

We log in with the user jenkins and access the folder:

Bash
root@jenkins:~# su – jenkins
root@jenkins:~# cd /var/lib/jenkins/.ssh

We generate the RSA key:

Bash
root@jenkins:~# ssh-keygen -t rsa

Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.

Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub.

We copy the key to the server where we are going to execute the script.

Bash
root@jenkins:~# ssh-copy-id root@192.168.1.57

We access the Jenkins server through our browser and click create a new task:

Captura de pantalla de 2015 02 18 115428

We assign the name of our project and select the first option.

Captura de pantalla de 2015-07-28 18:22:55

We go down to the section "Execute" and we select «Execute command line (shell)»

Command syntax: ssh <user>@<ip remote server> 'command'

Example: ssh  root@192.168.1.57 ‘nohup /root/test.sh’ &

Captura de pantalla de 2015-07-28 18:24:17

We click on our created job

Captura de pantalla de 2015-07-28 18:32:56

We execute in JOB > Build now, the job in execution will appear in the task history

We select the JOB running > Console Output

Captura de pantalla de 2015-07-28 20:08:19

It shows us the execution log:

Captura de pantalla de 2015-07-28 20:08:23

Regards, Rokitoh

:wq!

Comments