Jenkins package and push to remote server deployment and problems encountered

  • Download WAR package from official website
  • Configure the java environment and start: java -jar jenkins.war
  • Log in to the home page and follow the prompts to find the password to log in and set the username.
  • The next step is to download the plug-in, so don't download it now. Change the jenkins mirror address
#关闭jenkins进程,jenkins目录 war 启动 目录:/root/.jenkins/updates/default.json

sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.cloud.tencent.com\/jenkins/g' $JENKINS_HOME/updates/default.json

# 如果上边的命令updates.jenkins-ci.org 找不到, 换成 updates.jenkins.io
然后启动重新进入页面,下载插件,速度起飞
  • To configure various environments, home page Manage Jenkins => Global Tool Configuration What configuration needs to be run, there are a lot of searches on this Internet

  • The purpose I use here is to achieve local packaging and push to a remote server for release and operation. Install remote publishing plugin
    Insert picture description here

  • Configure remote server connection information Manage Jenkins = "System Configuration, two ways (password or key)

    Account password connection

Insert picture description here

Key connection

Insert picture description here

Key generation method, generated on the remote target server
Enter the command:, ssh-keygenfollow the prompts and keep Enter key to the end, press until as shown in the figure

Insert picture description here

1: Private and public keys will be generated in the .ssh directory
2: Copy the public key and rename the authorized_keys command:cp id_rsa.pub authorized_keys
3: Copy and fill in the content of the private key into the Key text box in the figure above, and test success!
  • Create a new task or first create an attempt (right arrow + sign) and then create an item, which is equivalent to grouping. The default creation is in ALL.

Insert picture description here

Create a task, build a Maven project

Insert picture description here

Configure the GIT connection address and user name information.

Insert picture description here
Insert picture description here

Insert picture description here

The following figure shows the key steps of remote push, pay attention to see in detail

name: It is the custom name of ssh configured in the previous steps, the drop-down box can be seen
Source files: Source files, this path, for example: For example, the location of my jar in the jenkins workspace is:, .jenkins/workspace/test-dt-service-member/dt-member/dt-member-service/target/dt-member-service-1.0.jarhere this address is filled in:dt-member/dt-member-service/target/*.jar
Remove prefix: When uploading to the target server, you need to remove the path before the jar package. The source file above says dt-member/dt-member-service/target/*.jarthat the prefix is ​​removed heredt-member/dt-member-service/target
Remote directory: upload to the directory of the target server, the previous ssh configuration information is /data, if you write a test here, then the file will be uploaded to the target server under /data/test
Exec command: Fill in the execution step command

Insert picture description here

The above information is configured, directly build and test

Problems that may arise:

1: Transfers 0 file, check the several issues about file paths mentioned above
2: During the execution of the script, the jenkins process will not be interrupted, keep logging in the log, turn on the advanced settings of the above picture, and check the options below

Insert picture description here

3: Jenkins during the build process, if the script spawned other processes, Jenkins finished will kill all processes in the execution of the script For example, I run a. sh start.sh, This script has a line java - jar ***.jarof command to start the project this time you will find Jenkins. It has been executed but the project did not start successfully. Just add nohup to the startup script.nohup sh start.sh

Jenkins executes the script without exiting, refer to this big guy

Guess you like

Origin blog.csdn.net/zhaojunjie_cc/article/details/109196440
Recommended