Jenkins + Python + GitLab continuous integration

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 URLthe input link Git repository.

If HTTP link, select the Credentialsrow Add > Jenkins, in Kinda line drop-down selection Username with password, below Usernameand Passwordenter your user name and password boxes.

Docker jenkins inside the container using ssh-key.
Direct use of the server ssh keyon it. If you specify a Path to keyneed to use dockerthe ssh key. If Source filesyou need to use the dockercontainer key, because the Source filesrelative path is not cured to a local path, but dockerthe path.

If a SSHlink, select SSH Username with private keyin Usernameenter a user name box, Private Keyselect as Enter directlythe display of keythe private key box. (Private keys are generated ssh-keygen -t rsa -C "email.com", the resulting file in a homedirectory .sshin the directory, use the command cat id_rsato view the private key, copied to the keybox). Click on the bottom of the Addbutton to save the settings.

In Credentialsthe 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, URLfollowed by a callback address, then click 高级, and then Secret tokenOK, click Generategenerated token.

In GitLabthe server corresponding items Settingsinside Integrations, configure webhook, input acquisition in jenkins in URL, and token, as needed check event, open SSL, click Add webhook. Will Add webhookgenerate 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, webhookthe configuration is complete.

Note: Using the script docker execexecution container command is not specified -it, -tspecified tty, and jenkinsno tty, you only need to specify -ito.

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 portto modify portthe port value), the generated public key stored in the target server. This free login password.

Install Publish over SSHplug-in 系统管理-> 系统设置find inside Publish over SSH.
Configuration Jenkins SSH Key, if the key password is set in the generation, just Passphraseenter the password, no it is ignored.
Private copy, paste into the Keyinside.

Configuration SSH Servers, click 增加. NameThe name of SSH, Hostnamethe IP address of the remote server, Usernamethe login user name, Remote Directorya directory on the remote server, must be real, plug-ins are not automatically created.

Click on Test Configurationtest 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 watchselect 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 Transfersthe Exec commandinput script commands, other options do not have to fill in temporarily.

Source filesIs relative to the workspacedirectory under the project directory, it is a relative directory, if the workspacedirectory, jenkinsworking directory, you need to fill out **/, may be followed by a file or files in the working directory folder.

Remove prefixTo filter the directory file copy.

Remote directoryFiles get to a directory on the remote machine, this directory is relative to SSH Serverthe 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 SSHplug-ins.

Click Credentials-> System-> Add domain, the Domain NameEnter the name, Descriptiondescription, write from time to write, Specificationkeep the default Add, click ok. In the new page, click the top left Add Credentials, enter the remote login Usernameand Passwordclick on OK.
Click 系统管理-> 系统设置to find SSH remote hosts, configure SSH site, click 增加, enter Hostnamethe host IP, Portremote port (usually 22), Credentialsjust create a selection Domain, and Usernamethe same click Check connection, display Successfull connection, successful, click 保存.

2.1 Remote deployment task

And basically 1.1the 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 Commandinput box shellscript. 保存It can be.

No sooner first constructed in this manner.

Configuring Mail

You can install Email Extension Pluginplug-ins, extensions mailbox function.

Click on the left side 系统管理, in 管理Jenkinsthe column clicking 系统设置, find a new page Jenkins Locationin 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 SMTPauthenticated 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 SSLprotocol, SMTPport 465, Reply-To Addressfill in the recipient address.

Premium-mail notification

You need to install the Email Extensionplug-in, installed, click 系统管理-> 系统设置to find Extended E-mail Notification, configure the SMTP serverserver, the format smtp.exmail.qq.com(here with Tencent E-mail as an example).

Default user E-mail suffixSet mail suffix, and behind the @ character is @xxx.com.

Default Content TypeSelect the default content type sent HTML/(text/html).

Default RecipientsDefault recipient may be provided a plurality of recipients, with the intermediate ,partition, the symbol of English state.

Default SubjectDo not change the default theme, you can also add some text at the top, for example 构建通知.

Default ContentThere 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 Usernameand Password, Passwordclient authorization and password to be 配置邮件in the same authorization code, check SSL, click 保存.

As a single Jobincrease 构建后步骤,
select Editable Email Notification, in Project Recipient Listthe 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 ListThe list of people allowed to return the default value $DEFAULT_REPLYTO.

Content TypeDocument type can be set HTML.

Attach Build LogMessages sent contains a log.

Click Advanced Settings, in Triggers, delete Sent Tothe default Developer List, click AddAdd Recipient List, save to complete.

Guess you like

Origin www.cnblogs.com/zzhaolei/p/11067999.html