Skip to content

Instantly share code, notes, and snippets.

@cidermole
Last active February 20, 2024 11:53
Show Gist options
  • Save cidermole/eccc5896658e4a99e674e20e80aafcb2 to your computer and use it in GitHub Desktop.
Save cidermole/eccc5896658e4a99e674e20e80aafcb2 to your computer and use it in GitHub Desktop.
Systemd service file for Jenkins agent on Ubuntu 20.04 Focal Fossa
# Steps to install Jenkins Agent using JNLP connection on Ubuntu 20.04 Focal Fossa
#
# * create an Agent node on the web GUI: https://wiki.jenkins.io/display/JENKINS/Step+by+step+guide+to+set+up+master+and+agent+machines+on+Windows
# * $ sudo apt-get install -y openjdk-14-jre-headless
# * $ sudo adduser jenkins
# * $ curl http://jenkins-master.internal/jnlpJars/agent.jar -o /home/jenkins/agent.jar
# * create systemd service: place this file in /lib/systemd/system/jenkins-agent.service
# * $ sudo systemctl enable myservice
# * $ sudo systemctl start jenkins-agent
[Unit]
Description=Jenkins Agent
After=network.target
Requires=network.target
[Service]
Type=simple
# optional file to provide environment variables (e.g. http_proxy, https_proxy):
#EnvironmentFile=/etc/sysconfig/jenkins
# TODO: adapt -jnlpUrl und -secret, as found on the web GUI: Jenkins > Nodes > ...
ExecStart=/usr/bin/java -jar /home/jenkins/agent.jar -jnlpUrl http://jenkins-master.internal:8080/computer/Linux/slave-agent.jnlp -secret 6bd5082ce1531212341234123412341234123412341234123412341234764898 -workDir "/home/jenkins"
Restart=always
User=jenkins
RestartSec=20
[Install]
WantedBy=multi-user.target
@busymans
Copy link

busymans commented Dec 2, 2022

Thanks a lot. You saved my day.

@asuna
Copy link

asuna commented Sep 2, 2023

Just a tip, if there is a '%' symbol in your .service file, it is necessary to insert an additional '%' to escape it.

@hariharanep4
Copy link

Thanks @cidermole for the service file and @asuna for the tip! It worked! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment