There are many related articles on the Internet, but I will mainly introduce the problem of Jenkins’ shell file authentication.
Project configuration
1. Plug-in download
Maven related plug-ins, Github related plug-ins, SSH related plug-ins. Specific plug-in names can be found online. If you don’t have the options below, it’s because you haven’t downloaded all the plugins.
2. Create a project
Select the Maven project and enter a name.
3. Source code management
Select Git and enter the SSH address of the Github project in the Repository URL.
Select Add Credentials, SSH type, and add the Github private key below.
Select GithubWeb in the source library browser at the bottom and enter the same url as the Repository URL at the top.
4. Build triggers
Check Build clean a SNAPSHOT dependency is built and GitHub hook trigger for GITScm polling
5. Build the environment
6. Post-build steps
Note: Jenkins destroys the project automatically after it is built, so set BUILD_ID to keep it.
Sh you are advised to store the. Sh file as/WWW/project name /deploy.sh to facilitate authorization execution. I ran into a number of potholes here, including insufficient execution permissions, BUILD_ID not working, projects still being destroyed, etc., which are eliminated when stored this way.
7. The shell file
Mainly for nohUP to persist the project.
Kill the original processPid = ` ps - ef | grep demo - hundreds - the SNAPSHOT. Jar | grep -v grep | awk'{print $2}'`
if [ -n "$pid" ]
then
kill9 -$pid
fi
## Transfer the generated JAR package
rm -f/ WWW/hyapp/demo - hundreds - the SNAPSHOT. Jar. The jar cp/var/lib/Jenkins/workspace/huya_app/target/demo - 0.0.1 - the SNAPSHOT. The jar / WWW/hyapp/demo - hundreds - the SNAPSHOT. Jar. The jar## nohup daemon started
exportBUILD_ID=dontKillMe nohup java-jar/WWW /hyapp/demo-0.0.2- snapshot.jar. Jar --server.port=8082 > / WWW /hyapp/hyapp.log 2>/www/hyapp/start.log&Copy the code
At this point, the project is built. If your Github push does not trigger the corresponding build task, you can manually build the project by clicking the small speaker on the right side of the project in Jenkins’ taskbar.