1. Preparation
Install java Configure JAVA_HOME
Install git
Install maven
Install tomcat
2. Install jenkins
This article uses je way to install jenkins, the war package download address: https://jenkins.io/zh/download/
Just need to put the downloaded jenkins.war under tomcat, after starting tomcat, visit http: // localhost: 8080 / jenkins
The first entry will let you configure the plugin (skip), administrator and other information;
3. Speed up by installing plugins
mac find /Users/didi/.jenkins/updates/default.json
window: C: \ Program Files (x86) \ Jenkins \ updates \ default.json
linux: /var/lib/jenkins/updates/default.json
modify: www .google.com changed to www.baidu.com
modified: updates.jenkins-ci.org/download changed to mirrors.tuna.tsinghua.edu.cn/jenkins
jenkins-> plugin manger> advanced> jenkins address changed to:
http: //mirror.xmission.com/jenkins/updates/update-center.json
need to restart the service
Enter the plugin service of jenkins again, download the corresponding plugin, the speed is very fast;
4. Configure jdk, maven
After entering the Global Tool Configuration:
5. Simple test maven project
6. Build project automation deployment
1. Install Publish over SSH plugin
2. Configure Publish over SSH, Configuration System
Note:
- Name: The hostname name of the configured tomcat service, and it is also configured in / etc / hosts of jenkins
- Hostname: tomcat address
- Username
- Remote Directory: Directory sent to the remote service
- Password: root password
3. Post Steps configuration
- Name: Choose what we configured above
- Source files: refers to the jar file directory generated by Jenkins packaging
- Remove prefix: relative to the current working directory to the current war package, the current directory is generally the directory of the file where the main project pom.xml is located. If not specified, the submaven / target directory will also be brought after upload, but here only the war package
- exec command: command to be executed
cd /usr/local/soft/tomcat-8.5.53
rm -rf webapps / demo-0.0.1-SNAPSHOT.jar
sh bin / shutdown.sh
sleep 3s
cp / usr / local / soft / demo-0.0.1-SNAPSHOT.jar webapps
sh bin / startup.sh
7. List of commonly used plugins for Jenkins
Users and permissions
GitHub Authentication https://plugins.jenkins.io/github-oauth, this plugin provides a solution for user authentication and authorization using GitHub .
Gitlab Authentication https://plugins.jenkins.io/gitlab-oauth, this plugin provides a solution for user authentication and authorization using GitLab .
Code management
Git https://plugins.jenkins.io/git, supports the use of Github, GitLab, Gerrit and other systems to manage code repositories .
Subversion https://plugins.jenkins.io/subversion, support Subversion system management source code .
Build trigger
Build periodically, Jenkins has a built-in function, you can set a time similar to crontab, and automatically trigger the build periodically.
Poll SCM, Jenkins built-in function, similar to Build periodically, you can set a time similar to crontab, the difference is not to build directly, but to periodically check whether the configured SCM is updated in the background, and only trigger when there is code update Construct.
Trigger builds remotely (eg, from scripts), Jenkins built-in functions, remotely trigger builds, you can support triggering Jenkins builds in remote scripts by setting the token.
GitLab https://plugins.jenkins.io/gitlab-plugin , this plugin integrates Jenkins into the GitLab web hook, and supports related events such as Gitlab branch and Merge Request to trigger Jenkins build.
GitHub Integration https://plugins.jenkins.io/github-pullrequest , this plugin integrates Jenkins into GitHub, supports Gitgub branch and Pull requests to trigger Jenkins build.
Build tasks and environment
Workspace Cleanup https://plugins.jenkins.io/ws-cleanup, this plugin supports deleting or partially deleting workspace
Environment Injector https://plugins.jenkins.io/envinject before and after construction , this plugin supports different stages of the build task Insert environment variables, and export all environment variables and other functions at the end of construction .
deploy
Deploy to container Plugin supports deploying code to tomcat container
Reference: https://blog.csdn.net/pansaky/article/details/80755739
Reference: https://www.jianshu.com/p/e0b7d377132a