============================= Automated builds with Jenkins ============================= Prerequisites ============= 1. Install Jenkins on a RaspberryPi ------------------------------------ Look for the lastest version mathcing your OS version (source used for this: https://orcacore.com/jenkins-server-installation-debian12/) Add Jenkins to Debian: ______________________ - Add the official Jenkins repository to your Debian 12. Add the GPG key repo with the following wget command: .. code-block:: bash sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \ https://pkg.jenkins.io/debian/jenkins.io-2023.key - Then, add the long-term support version of the Jenkins repo with the command below: .. code-block:: bash echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null Jenkins server installation on Debian _____________________________________ 1. Create a shell script to start the agent (optional if using master with an executor) ---------------------------------------------------------------------------------------- - create a new agent, add name and description - install the same java version (used for the server) on the agent - copy the snipet from the jenkins agent configuration page - save it in a new file on the agent and make it executable 3. Create credentials to be used for checkout of Git repositories ------------------------------------------------------------------ - Create a new Job ================ 1. Set up Git as SCM and enter the right Repository URL to the github repo. 2. Use the credentials created before. 3. Specify the correct Branch to Build, main not master. 4. Select "GitHub hook trigger for GITScm polling" in Build Triggers. 5. Select "Delete workspace before build starts" in Build Environment 6. Create a new Build Step "Execute shell" with the following content: .. code-block:: bash #!/bin/bash echo starting build cd /home/user/virtEnv source Website/bin/activate echo activated virtualenv sphinx-build /home/user/ws/workspace/build_sphinx_and_replace_html/source /home/user/myApp/_build echo built website 7. Save and Build to test. Webhooks for github =================== Configure a new webhook for the concerned repo. Provide URL to the Jenkins server and append "/github-webhook/". It will work as soon as the server is reachable remotely. Common pitfalls =============== Issues encountered and how they have been fixed. Invalid X-Instance-Identity --------------------------- .. code-block:: bash ~ $ sudo ./start_agent.sh Jun 01, 2024 6:59:39 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir INFO: Using /home/user/ws/remoting as a remoting work directory Jun 01, 2024 6:59:40 AM org.jenkinsci.remoting.engine.WorkDirManager setupLogging INFO: Both error and output logs will be printed to /home/user/ws/remoting Jun 01, 2024 6:59:40 AM hudson.remoting.Launcher createEngine INFO: Setting up agent: agent_name Jun 01, 2024 6:59:40 AM hudson.remoting.Engine startEngine INFO: Using Remoting version: 3206.vb_15dcf73f6a_9 Jun 01, 2024 6:59:40 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir INFO: Using /home/user/ws/remoting as a remoting work directory Jun 01, 2024 6:59:41 AM hudson.remoting.Launcher$CuiListener status INFO: Locating server among [http://192.168.xxx.xxx:xxxx/] Jun 01, 2024 6:59:41 AM org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver resolve INFO: Remoting server accepts the following protocols: [JNLP4-connect, Ping] Jun 01, 2024 6:59:41 AM hudson.remoting.Launcher$CuiListener status INFO: Could not locate server among [http://192.168.xxx.xxx:xxxx/]; waiting 10 seconds before retry java.io.IOException: http://192.168.xxx.xxx:xxxx/tcpSlaveAgentListener/ appears to be publishing an invalid X-Instance-Identity. at org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.resolve(JnlpAgentEndpointResolver.java:277) at hudson.remoting.Engine.innerRun(Engine.java:809) at hudson.remoting.Engine.run(Engine.java:563) **Solution: Installing plugin "Instance Identity"** Provided port:xxxxx is not reachable on host 192.168.xxx.xxx ------------------------------------------------------------ .. code-block:: bash ~ $ sudo ./start_agent.sh Jun 01, 2024 7:17:44 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir INFO: Using /home/user/ws/remoting as a remoting work directory Jun 01, 2024 7:17:44 AM org.jenkinsci.remoting.engine.WorkDirManager setupLogging INFO: Both error and output logs will be printed to /home/user/ws/remoting Jun 01, 2024 7:17:44 AM hudson.remoting.Launcher createEngine INFO: Setting up agent: agent_name Jun 01, 2024 7:17:45 AM hudson.remoting.Engine startEngine INFO: Using Remoting version: 3206.vb_15dcf73f6a_9 Jun 01, 2024 7:17:45 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir INFO: Using /home/user/ws/remoting as a remoting work directory Jun 01, 2024 7:17:45 AM hudson.remoting.Launcher$CuiListener status INFO: Locating server among [http://192.168.xxx.xxx:xxxx/] Jun 01, 2024 7:17:54 AM org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver resolve INFO: Remoting server accepts the following protocols: [JNLP4-connect, Ping] Jun 01, 2024 7:17:59 AM org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver isPortVisible WARNING: Connect timed out Jun 01, 2024 7:17:59 AM hudson.remoting.Launcher$CuiListener status INFO: Could not locate server among [http://192.168.xxx.xxx:xxxx/]; waiting 10 seconds before retry java.io.IOException: http://192.168.xxx.xxx:xxxx/ provided port:xxxxx is not reachable on host 192.168.xxx.xxx at org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.resolve(JnlpAgentEndpointResolver.java:304) at hudson.remoting.Engine.innerRun(Engine.java:809) at hudson.remoting.Engine.run(Engine.java:563) **Solution: adjust iptables on master:** .. code-block:: bash $ sudo iptables -I INPUT -p tcp -m tcp --dport port_number -j ACCEPT