当前位置:网站首页>Jenkins node project auto build configuration

Jenkins node project auto build configuration

2020-12-08 10:23:26 Fresh water

One Jenkins A new task

image.png

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 .

image.png

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 .

image.png

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

image.png

Click Save app . And then back to the main panel .
Click item to enter the project panel . Click on Build Now Build immediately .

image.png

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 .

image.png

Click the drop-down box after the error list in the lower left corner and select console output to view the error log

image.png
image.png

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 .

image.png

As expected, there is no , We build new website Folder .

mkdir website

go back to Jenkins Build it again .

image.png

Building a successful , Look at the console output .

image.png

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 .

image.png

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 .

image.png

choice webhooks And click the add webhook

image.png
image.png

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 .
configured .

版权声明
本文为[Fresh water]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/202012081022593080.html