Master Jenkins CI for SpringBoot: From Build to Remote Deployment
This guide walks you through configuring Jenkins to build a SpringBoot Maven project, automating post‑build steps, managing the workspace, and securely transferring the resulting JAR to another server using SSH keys or an Expect script.
This article explains how to set up Jenkins for a SpringBoot Maven project, covering job creation, source code configuration, build commands, and post‑build actions.
The project resides at https://gitee.com/xuliugen/ufind-server. After ensuring Jenkins is installed, create a new job (ignore the "already exists" warning) and configure the following:
Project name and description.
Git repository URL and credentials.
Build step: mvn clean package -Dmaven.test.skip=true (skips tests).
Post‑build step: custom shell script to copy the generated JAR, set export BUILD_ID=dontKillMe, kill any previous process, and start the new JAR in the background while recording its PID in ufind-web.pid.
The Jenkins workspace is located at
/home/xuliugen/.jenkins/workspace/ufind-server/ufind-web/target, where the compiled JAR appears.
To move the JAR to another server, use scp. Because scp prompts for a password, two methods are presented:
Establish password‑less SSH trust : generate an RSA key pair with ssh-keygen -t rsa, copy the public key to the remote host's ~/.ssh/authorized_keys (or use ssh-copy-id), and repeat for bidirectional trust.
Use an Expect script : install expect and write a script that automates the password prompt. Key commands are send, expect, spawn, and interact. Example snippets are shown in the original images.
After setting up the trust or Expect automation, the JAR can be transferred and started on the remote host (e.g., 192.168.1.241) via a remote startup.sh script.
All configuration steps are now complete, and the SpringBoot service can be accessed through a browser.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
