preface

This article describes how to use Jenkins to automatically deploy gradle-based SpringBoot projects. The Jenkins service is running on a Win10 vm, the deployed project is running on a Linux server machine, and the project is hosted on GitHub.

Download and run Jenkins

You can also configure the JENKINS_HOME environment variable, which will be used to store Jenkins files in the following locations (you can choose your own location here). Generally not recommended system disk, there may be permission problems, because I use the virtual machine environment test, so it is optional) :

Then run Jenkins using the java-jar jenkins.war command (port 8080 is enabled by default, if you want to specify another port, Java-jar Jenkins. War –ajp13Port=-1 –httpPort=8081 java-jar Jenkins. War –ajp13Port=-1 –httpPort=8081

Wait a moment and the console will print the default administrator address:

Then enter http://localhost:8080 in your local browser to access:

Fill in the password just printed on the console, and then click continue. After a while, the following interface will appear, prompting you to install plug-ins. Select recommended installation here:

Then you need to download and wait:

Then you can choose to create a new user:

The startup port configuration remains the same:

Click “Save” and complete the basic configuration. You can enter the home page:

Environment configuration

And then clickManage JenkinsAfter clickingManage Plugins:

Then click to download SSH related plug-ins in the order shown in the diagram:

Then go back to the home page and click Manage Jenkins and then Global Tool Configuration:

Git, Gradle, JDK

Then go back to the home page and click Manage Jenkins and then Manage Credentials:

Click Global and select Add Credentials:

Enter your GitHUb account information here and click OK:

Then create an SSH server account information credential:

Then go back to the home page and click Manage Jenkins and then click Configure System:

First, configure SSH remote hosts:

Then scroll down to configure Publish over SSH and click on the add under SSH Servers:

Enter the IP address of the server and the root path of the server.

Then click “Advanced” in the lower right corner and check “Use password” :

Click Save and return to the home page.

Project build configuration

First click on new Item:

Then enter the task name and select Freestyle Project and click OK:

First, configure the git address of the project in the source code management (I use the pre-built demo project here, the steps and content of the project will not be introduced) :

Add gradle script execution step to build:

Then configure:

Then add the send file build step again:

Configure the jar directory and upload it to the root directory of the server:

Then add the build step again and add the script that needs to be run on the server:

Then configure the commands to execute:

Save the configuration and return to the home page.

Run the deployment

On the home page, click the “Execute” icon after creating a new task:

Then click the execution progress bar in the lower left corner:

Then click the progress bar in the lower left corner again:

Then click on the console output to see the related log information:

You can use curl on the server to verify:

You can see that the contents of the interface are printed correctly: