Jenkins version 2.277.4

Docker version 20.10.5

Jenkins Chinese website – >

Install Jenkins

Docker installation is all so simple, pay attention to check whether 8080 is occupied!

docker run --name jenkins -u root --rm -d -p 8080:8080 -p 50000:50000 -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

If the port number is not changed, after the installation, visit the address -> http://{and deploy Jenkins’ service IP}:8080

Initialize the Jenkins

See website tutorial – >…

The first simple task

Start by creating a simple task that executes a shell script or Linux command for the server. Since Jenkins is deployed in the Docker container, it is not possible to directly execute shell scripts on the host, so SSH is required to login to the host for execution. This requires the Publish Over SSH plug-in. In the same way, if Jenkins and your project are not on the same server, you can use the plug-in to remotely copy packaged files or execute scripts.

Installing a plug-in

Home -> System Administration -> Plug-in Management -> Search Publish Over SSH and install.

Publish Over SSH

Home -> System Management -> System Configuration ->

Create a task

Home -> New Task -> Fill in the Task Name -> Selection: Build a Free Style Software Project

Go directly to the Build TAB and click Add Build Steps to selectSend files or execute commands over SSH

Under SSH Service, select the server you just configured in System Configuration.

The Exec command column directly type the command can, may wish to tryecho $(pwd)Command.

Save, the first task has been created successfully, go back to the task details page, click build now, go to the “console output” to see the execution details.

Create a task to automate the deployment of a Maven project

How it works: Jenkins pulls the project down with the Git plugin, packages it with the Maven Integration plugin, sends the packaged JAR or folder to the server where the project is deployed with the Publish Over SSH plugin, and executes a shell script to launch ~


  1. Git plugins: installed by default when initialized;
  2. Maven Integration Plug-in: the same installation method as above;
  3. Maven configuration: Home page -> system management -> global tool configuration, tick automatic installation, select Maven version;
  4. Publish Over SSH: create last task installed/configured

Git pulls code

To create the same task, go to the Configuration page and go to the Source Management TAB to configure the repository address and key:

At that point you can save it and hit Build Now and see if you can pull it down.

Maven packaging

Go to the Build TAB, click Add Build Steps and select Call Top Level Maven Target.

If you don’t have it, you don’t deserve it. No, you don’t!

In the target field, enter the packaging command: clean install -dmaven.test. skip=true, or enter as appropriate.

At this point you can save it and hit Build Now to see if the code packages properly.

Run the startup script

Send Files or Execute Commands over SSH/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands/Commands Source Files and Remote Directory were used to transfer JAR files, but I deployed Jenkins’ Docker on the same server as I deployed the project. The JAR files in the Docker container could be copied by using docker cp command. Write it with the script that starts the project. You can skip the file transfer and just execute the script. See “Manji Docker CP” for details.

A task to automate the deployment of a Maven project is created

Send Files or Execute Commands over SSH file transfer capabilities

Source files: This is the root directory where the code is pulled down. If you want to transfer the folder, use ** to denote Remote directory (home directory for logging in to the project server) : This directory is /root, and files can only be transferred to this directory or to directories below this directory! Exclude files: Exclude files that will not be transferred. Unneeded files such as and.gitignore can be separated by a comma to ensure that the Pattern separator is configured as [,]+

Matters needing attention

  1. Mysql > Publish Over SSH: mysql > Publish Over SSH: mysql > Publish Over SSH: mysql > Publish Over SSH: mysql > Publish Over SSH: mysql > Publish Over SSH: mysql > Publish Over SSH: mysql > Publish Over SSH:
  2. Send Files or Execute Commands over SSH Remote Directory can only be configured to be the user’s home directory!
  3. Jenkins deployed by Docker cannot directly run shell scripts on the host, and the pulled code and packaged files are all in the Docker container! Use the Publish Over SSH plug-in.
  4. The host does not need to install Git or Maven!
  5. If executing the script directly to launch the JAR works, Jenkins executes the script to report an errornohup: failed to run command java: No such file or directory, plus a line in frontsource /etc/profileIt can be solved.