Create a task
Log in Jenkins
, click on the left-hand list of 新建
options. Enter the task name, select 构建一个自由风格的软件项目
, click 确定
.
Configuration
In the 任务配置
interface, you can set General标签
the 丢弃旧的构建
options, settings 保持构建的天数
and 保持构建的最大个数
.
Click on 源码管理
the tab, choose git
, in Repository URL
the input link Git repository.
If HTTP link, select the Credentials
row Add > Jenkins
, in Kind
a line drop-down selection Username with password
, below Username
and Password
enter your user name and password boxes.
Docker jenkins inside the container using ssh-key.
Direct use of the server ssh key
on it. If you specify a Path to key
need to use docker
the ssh key
. If Source files
you need to use the docker
container key
, because the Source files
relative path is not cured to a local path, but docker
the path.
If a SSH
link, select SSH Username with private key
in Username
enter a user name box, Private Key
select as Enter directly
the display of key
the private key box. (Private keys are generated ssh-keygen -t rsa -C "email.com"
, the resulting file in a home
directory .ssh
in the directory, use the command cat id_rsa
to view the private key, copied to the key
box). Click on the bottom of the Add
button to save the settings.
In Credentials
the drop-down menu to select just created Username
.
Use regular task
In the 构建触发器
tag selection Poll SCM
, input H/2 * * * *
, and finally click 保存
.
This is a timed task, the query code once every two minutes, if an update on the implementation of tasks.
Use webhook
Webhook better than using regular tasks, webhook only when the specified operation or push, pull Jenkins will code, not the timing of access, resource-intensive.
You need to install the plug-in Gitlab Hook、GitLab、Gitlab Authentication、Build Authorization Token Root
configuration job
, in 构建触发器
the check Build when a change is pushed to GitLab. GitLab CI Service URL: http://服务器IP:8080/project/demo
, URL
followed by a callback address, then click 高级
, and then Secret token
OK, click Generate
generated token
.
In GitLab
the server corresponding items Settings
inside Integrations
, configure webhook
, input acquisition in jenkins in URL
, and token
, as needed check event, open SSL, click Add webhook
. Will Add webhook
generate a next button webhook
, click test
, pop-up check of the event, select the event will pop up in the top Hook executed successfully: HTTP 200
, this, webhook
the configuration is complete.
Note: Using the script docker exec
execution container command is not specified -it
, -t
specified tty
, and jenkins
no tty
, you only need to specify -i
to.
1 will deploy the code to a remote server
Without using ssh-key container.
Jenkins server generated on the Key ssh-keygen -t rsa -C "email.com"
,
used ssh-copy-id -i ~/.ssh/id_rsa.pub user@ip
(if not port 22, the parameter may be added -p port
to modify port
the port value), the generated public key stored in the target server. This free login password.
Install Publish over SSH
plug-in 系统管理
-> 系统设置
find inside Publish over SSH
.
Configuration Jenkins SSH Key
, if the key password is set in the generation, just Passphrase
enter the password, no it is ignored.
Private copy, paste into the Key
inside.
Configuration SSH Servers
, click 增加
. Name
The name of SSH, Hostname
the IP address of the remote server, Username
the login user name, Remote Directory
a directory on the remote server, must be real, plug-ins are not automatically created.
Click on Test Configuration
test configuration was successful. Success will be displayed Success
.
1.1 Remote deployment task
Then create a build task, the task is triggered when a building task runs.
Or click 新建
, enter a name for the task, do not click 构建一个自由风格的软件项目
, triggering the task name at the bottom of the copy box, enter just created.
Click 确定
. If the task name entered does not exist, an error, and allows you to re-enter again.
In 构建触发器
the selection Build after other projects are built
, carried out after the completion of the project to build other, Projects to watch
select the first task may be error No such project ‘gol’. Did you mean ‘golismero’?
, it does not matter if it is a single task, you can put the final surface of the ,
comma and a space deleted, it does not complain, do not delete nor influences.
Check the following Trigger only if build is stable
, only triggered when the building is stable.
Other settings, 构建后操作
in 增加构建后操作步骤
the pop-up option is selected Send build artifacts SSH
, the input SSH Server Name
(remote host IP), and then in Transfers
the Exec command
input script commands, other options do not have to fill in temporarily.
Source files
Is relative to the workspace
directory under the project directory, it is a relative directory, if the workspace
directory, jenkins
working directory, you need to fill out **/
, may be followed by a file or files in the working directory folder.
Remove prefix
To filter the directory file copy.
Remote directory
Files get to a directory on the remote machine, this directory is relative to SSH Server
the Remote directory
, if not present will be created automatically.
Save, you can see the trigger tasks and build tasks.
There is another way that can be deployed
2 SSH plug-in deployment
In this way you need to install SSH
plug-ins.
Click Credentials
-> System
-> Add domain
, the Domain Name
Enter the name, Description
description, write from time to write, Specification
keep the default Add
, click ok
. In the new page, click the top left Add Credentials
, enter the remote login Username
and Password
click on OK
.
Click 系统管理
-> 系统设置
to find SSH remote hosts
, configure SSH site
, click 增加
, enter Hostname
the host IP, Port
remote port (usually 22), Credentials
just create a selection Domain
, and Username
the same click Check connection
, display Successfull connection
, successful, click 保存
.
2.1 Remote deployment task
And basically 1.1
the same, but this is 构建
in 增加构建步骤
the pop-up option is selected Execute shell script on remote host using ssh
, the default will automatically fill in SSH site
(if not filled in, click on the input box to see if there if there is no error possible in front), there may be a red error SSH Site not specified
, not management. In the Command
input box shell
script. 保存
It can be.
No sooner first constructed in this manner.
Configuring Mail
You can install Email Extension Plugin
plug-ins, extensions mailbox function.
Click on the left side 系统管理
, in 管理Jenkins
the column clicking 系统设置
, find a new page Jenkins Location
in the 系统管理员邮件地址
Enter the sender column format 标题<email.com>
, and then find 邮件通知
and click 高级
the button to add SMTP服务器
, as well as e-mail suffix ( @xxx.com
), using the SMTP
authenticated user name is the complete e-mail account, The password is an authorization code. (Tencent micro-bound E-mail if the letter in Settings - Binding Letter micro - Client-specific password, authorization code, save the settings.) Check to use SSL
protocol, SMTP
port 465
, Reply-To Address
fill in the recipient address.
Premium-mail notification
You need to install the Email Extension
plug-in, installed, click 系统管理
-> 系统设置
to find Extended E-mail Notification
, configure the SMTP server
server, the format smtp.exmail.qq.com
(here with Tencent E-mail as an example).
Default user E-mail suffix
Set mail suffix, and behind the @ character is @xxx.com
.
Default Content Type
Select the default content type sent HTML/(text/html)
.
Default Recipients
Default recipient may be provided a plurality of recipients, with the intermediate ,
partition, the symbol of English state.
Default Subject
Do not change the default theme, you can also add some text at the top, for example 构建通知
.
Default Content
There is a default template, the template can be found on the Internet changes, you can also write your own, html type.
Click the above 高级
button, check Use SMTP Authentication
, type Username
and Password
, Password
client authorization and password to be 配置邮件
in the same authorization code, check SSL
, click 保存
.
As a single Job
increase 构建后步骤
,
select Editable Email Notification
, in Project Recipient List
the input list of recipients in the recipient's mailbox, you can use multiple ,
division, want to use the global default configuration, you can use $DEFAULT_RECIPIENTS
.
Project Reply-To List
The list of people allowed to return the default value $DEFAULT_REPLYTO
.
Content Type
Document type can be set HTML
.
Attach Build Log
Messages sent contains a log.
Click Advanced Settings
, in Triggers
, delete Sent To
the default Developer List
, click Add
Add Recipient List
, save to complete.