Jenkins (3) Jenkins automatically publishes to the test server and runs automatically

test server

Prepare a test server (Linux)

You only need to install JDK on this test server

Next, what we need to do is to publish the jar package obtained by running it before (Jenkins (2)) to this server and run it automatically.

Install plugin (publish over ssh)

We installed the Maven plug-in before

We now need to install the "publish over ssh" plug-in

Follow the previous steps to install this plug-in, as follows:

Insert image description here
Successful installation
Insert image description here

Reconfigure

Return to the Dashboard and click the project name "first"
Insert image description here
After that, the following interface will appear, select Configuration
Insert image description here
After clicking the "Configuration" option , the following content appears, click "Post Steps" directly to enter the following page
Insert image description here

Post Steps

In this option, select "Send files or execute commands Over SSH". This is the plug-in we installed before. After clicking, the following content that we need to configure will appear.
Insert image description here

Now, this server address cannot be selected yet, so we first need to configure it.

Configure System (add a target server)

Select global configuration,
Insert image description here
In this, find "publish over ssh"
Insert image description here
Next, click "New"< a i=3> The following interface appears Enter the server name (xxx), ip (such as xx.xx.xx.xx), account (root), Remote Directory (optional)
Insert image description here

Insert image description here

Scroll down and select "User xxx"
Insert image description here
Just enter the password of the previous account in "Passphrase / Password". You don't need to worry about the other things in this tab.

After filling in the above, scroll down and you can select the port, etc.

Insert image description here
Scroll down again, here you can set up the springboard machine, etc.
Insert image description here
After all settings are completed, there is a Test Configuration, click to try to see if you can connect
Insert image description here
Run successfully
Insert image description here

If it fails (the password is entered incorrectly), the following content will appear
Insert image description here

Change setting

Go back to where you set Post Steps before, and now you can select the server, as follows
Insert image description here

Scroll down and configure the source file: throw all jar files in the current directory to the server configured above

Insert image description here
Ignore the following two "Remove xx" for now.

"Remote directory": Which directory to send the previously sent files to. If this directory does not exist, it will automatically create a directory.
Insert image description here

Exec command: After the transmission is completed, on the target server, you want to execute the above command
Here, simply enter a line of command "echo 1"
Insert image description here
Afterwards, save

implement

Execute it again
Insert image description here
Check the console output
Insert image description here
Find out by checking the logTransferred 0 file(s)

It means that not a single file has been transferred.

But looking at the log, the jar package has been packaged successfully.

I checked the log again and found that there was an error in the "Source files" set previously.

Modify the configuration to: match all directories, all jar packages starting with demo
Insert image description here
Rerun
Insert image description here

View log
Insert image description here

Whether the file has been transferred

It can be found from the log that the file was transferred. You can view the file by entering the test server, and there is no problem running it.

View Files
Insert image description here

View catalog
Insert image description here

Other issues modified

There was a problem with the directory passed before, so we still need to modify the previous configuration.

  1. Modify root/root/xxx to root/xxx
  2. Modify the previous /demo-1/target and change it to root/xxoo/xx.jar

Insert image description here
Delete the contents of the directory that reported errors before

Save, then re-run and find that the problem is solved

jar package location

Insert image description here

automatic running

This configuration should be modified based on the previous configuration.

Insert image description here
Save it and delete the corresponding files on the test server.

Then run it directly
Insert image description here
Check the console output
Insert image description here
Now the jar package has been started

Guess you like

Origin blog.csdn.net/yyuggjggg/article/details/126716984#comments_29571566
Recommended