One Jenkins A new task
Enter task name , Choose to create a free style project .
Two Task build configuration
The author uses git, Here we use git As an example .
Enter the git Address , And for logging in git Account and password . Specify the branch and choose the one you want to build git Branch .
Check the build trigger , be used for git The updated code will be automatically pushed to jenkins An automated build .
Add build step selection ：Execute shell
Input shell command
npm install rm -rf ./dist/* npm run build rm -rf /usr/local/tomcat/webapps/website/* cp -rf ./dist/* /usr/local/tomcat/webapps/website
Click Save app . And then back to the main panel .
Click item to enter the project panel . Click on Build Now Build immediately .
Build complete , However, the construction history in the lower left corner explodes, indicating that the construction failed . Click on the right side of the workspace to see the project , Description from git Address, user name, account no problem .
Click the drop-down box after the error list in the lower left corner and select console output to view the error log
error found ,website Not a directory , It means that on our server tomcat webapps There is no such document . Log in to the server and check .
As expected, there is no , We build new website Folder .
go back to Jenkins Build it again .
Building a successful , Look at the console output .
From the console, you can see that the file has been packaged successfully , And it's been put into tomcat Next , Get into tomcat Let's have a look .
ha-ha , That's what we want .
start-up tomcat Visit and try it ！
3、 ... and To configure Git Automatically build after update
Sign in github And select to project warehouse , Click Settings .
choice webhooks And click the add webhook
payload URL：Jenkins Server address + Port number +/github-webhook.
increase webhook after , When the code is submitted, it will pass webhook tell Jenkins Come and pull the code and build it automatically .