In this tutorial, you will learn how to start a Jenkins agent as a Linux service. This tutorial is going to be a simple step-by-step guide.
Create a directory called Jenkins in your home directory or anywhere with any name.
Download your agent.jar file into this directory.
Now create a
slaveStart.sh file with your Jenkins start script which you can grab from your Jenkins master.
java -jar agent.jar -jnlpUrl https://arjunphp.com:8443/computer/Ubuntu-10.1.0.172/slave-agent.jnlp -secret 44787c299136da39b30af3449a833500c994d946222d281a194d551c24080f88 -workDir "/home/ubuntu/jenkins" exit 0
Make the script executable by executing
chmod +x slaveStart.sh
/etc/systemd/system/jenkins-slave.service a file with the following content.
sudo vim /etc/systemd/system/jenkins-slave.service
[Unit] Description=JenkinsSlave [Service] User=ubuntu WorkingDirectory=/home/ubuntu/jenkins ExecStart=/bin/bash /home/ubuntu/jenkins/slaveStart.sh Restart=always [Install] WantedBy=multi-user.target
Enable the daemon with the following command.
sudo systemctl enable jenkins-slave.service
Now start the daemon with the following command.
sudo systemctl start jenkins-slave.service
Check the status with the below command and about should be similar to the below image.
sudo systemctl status jenkins-slave.service
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.