jenkins maven automatically published to the remote server, nail remind team

Original link: http://www.cnblogs.com/Halburt/p/10709674.html

jenkins automatically published to the remote server

1. Install jenkins

Installation: Self Baidu

English is not good, do not install the latest version of jenkins. Recommended to install Jenkins ver. 2.138.4, this version can be set up Chinese language, setting as
image.png

2. Install the main plug

System Management> Plug-In Manager, an optional plug-in, the search plugin
image.png

1)Publish Over SSH

Send build artifacts over SSH
for uploading released after the construction of war, jar packages and other resources, and then execute the command server script, very powerful

2) Dingding [nail] Plugin

image.png
Plug nails notification. Used to construct after completion notification message.

3. Configuration Environment

After the plugin is installed, you need to configure the environment.

1) System> Settings

image.png

  • Hostname: host address (ip or domain name)
  • Port: Port number
  • Root Repository Path: The default directory after the connection
  • User Name: User Name
  • Password / Passphrase: password keys
2) System Management> Global Configuration Tool
Maven configuration information:

Set setting file
image.png
to set maven installation directory
image.png

Configuring JDK

Configuring jdk installation directory
image.png

4. Create a job

1) Create a Job, called MyTestJob

You can customize the task name, select the [construct build a free-style software project]
image.png

2) Set Construction

If disk space is small, where you can set up automatic deletion policy. FIG set, expressed reservations constructs 2 days, up to 2
image.png

3) Source Management

Local use SVN, so to SVN for example.
image.png

Repository URL: SVN的资源地址,路径直接到项目路径【本文演示的也是maven项目】如:项目名称为myProject,那么svn地址就要写到myProject,https://192.168.1.XXX:XXX/svn/XXX/XXX/myProject
Credentials: 先添加个SVN账号,点add
image.png
ID设置一个唯一的,其他就是用户名密码。
设置完成之后,就可以下拉选择
image.png
其他的就默认

4)构建触发器

定时构建: 不管SVN或Git中数据有无变化,均执行定时化的构建任务 ;

轮询SCM: 只要SVN或Git中数据有更新,则执行构建任务;

构建语法说明:

格式为:* * * * (五个星);
第一个
表示分钟,取值0~59
第二个表示小时,取值0~23
第三个
表示一个月的第几天,取值1~31
第四个表示第几月,取值1~12
第五个
表示一周中的第几天,取值0~7,其中0和7代表的都是周日

使用举例

每隔10分钟构建一次:H/5 * * *
每隔1小时构建一次:  H H/1 
*
每月30号构建一次:    H H 30
*

定时构建和轮询SCM使用互不冲突,可以需要根据项目情况配置。我这里测试环境使用【轮询 SCM】已经能满足需求。每五分钟检查一次svn更新,如有更新则进行构建。
image.png

5)构建

其实构建之前可以设置构建环境,可以根据项目需要去设置。
基于maven可以使用maven进行构建
image.png
Maven 版本: 选择之前配置的maven版本
目标: 设置maven构建语句【不用写mvn】
image.png
配置完maven信息之后,新增ssh配置:
image.png

上传服务器文件路径说明:

最终上传到服务器的文件路径为:
系统设置里的Remote Directory + 构建里的 Remote Directory + Source files
如图即为:A + C + B
image.png
Source files: 相对于workspace目录,其实也就相当于在myproject目录下,maven构建之后,会在该目录下生成target目录,所以此处可以填写target\XXX.war
Remove prefix: 移除Source files的前缀。填写target 如果删除target的话,最终上传的时候也会带着target目录
Remote Directory: 在系统设置里的Remote Directory 下,生成此处的Remote Directory目录
Exec command: 上传之后执行的命令行,可以在服务器制作sh脚本,比如停止tomcat,拷贝war包到tomcat,然后启动tomcat。
此处命令后期可以在补充上。

6)构建后操作

当然jenkins自动帮我们发布了,我们不可能时时刻刻都盯着jenkins控制台,我们需要它提醒我们,我们可以选择配置邮件提醒等等,为了方便,我们可以使用钉钉通知。

钉钉群设置

image.png
Creating a team nailed group, add [group] robot in the nail group settings, click Add
image.png
to select the custom, after setting picture and name
image.png
will get a url after
https://oapi.dingtalk.com/robot/send?access_token XXXXXXXXXX =
the access_token following parameter settings required

Nail notification settings

After the construction of the new operation, select the order notification.
image.png

jenkins URL: Enter the address of course jenkins access
nailing access token: is the url nails robot group in the access_token parameter
other is to choose robot nails reminder time. After the addition is complete, jenkins building will be a timely reminder of the team members.

Reproduced in: https: //www.cnblogs.com/Halburt/p/10709674.html

Guess you like

Origin blog.csdn.net/weixin_30588907/article/details/94785389