The late scholar notes --Jenkins + Git + Gitlab + Ansible achieve continuous integration automated deployment static websites

Jenkins + Git + Gitlab + Ansible achieve continuous integration automated deployment static websites

 

One. Jinkens installation                                                     

Under jinkens installation package

 

 

With 18 years of relatively stable

 

 

 

Installation gitlab and jinkens

 

 

 

 

 

 

 

Do not use the Network source the Java , the online version of the Java version higher, with jenkins not compatible.

The installation, view the port: 80 whether to open, listening 8080

 

 

Modify the port:

 

 

 

Restart Jenkins

 

Two . Site Actions                                                            

Site Actions setup is complete gitlab :

 

 

slightly

Site Actions and then Jenkins : direct input access port Local address: 8081 (modified)

 

 

 

Copy the key in this file to a blank box

 

 

 

Then jump interface may be two kinds:

1. The first: the following, click on the right side of the module:

 

 

Figure Hits:

 

 

 

2. The second:

 

 

 

2 Zhong eventually jump to the page :

Fill in the information, click Finish

 

 

Click Start to complete:

 

 

 

Hits: System Management - "Plug

 

 

Click 'already installed': display plug is empty

 

 

Download plug-in package, upload, and do the following:

 

 

ls it will see a lot of plug-ins, restart Jenkins , then re-enter the Jenkins web site, you will find a bunch of plug-ins:

 

 

 

three. A simple demonstration of the establishment of the task:                                                                  

 

 

 

 

 

 

 

 

 

 

Write shell commands, you can view the environment variables (such as ' Workspace '):

 

 

 

Remember to save:

 

 

 

 

 

Click 'Create now', wait for a while, there will be a blue standard ,, represents the creation of a successful

 

 

Click on the blue ball

 

 

Credentials credentials

Creating credentials as click:

 

 

 

 

 

 

 

 

 

four. Examples of projects:                                                                     

1. built gitlab Project Name:

 

 

 

 

 

 2.yum install ansible

 

 3. Pull the remote git repository

 

 

Ansible deployment of roles

 

 

Edit the host group deployment, 'for Inventory,' fixed, 'test' can easily write:

 

 

Edit Tasks :

 

 

 

注意:请确保server机有nginx,没有请先下载

将要复制的文件放入模板文件下,并编辑文件:

 

 

 

加入变量:

 

 

 

 

编辑varsyml文件

 

 

 

编辑files下文件:

 

 

 

最后编辑启动文件:

 

 

 

发送密钥:

 

——#ssh key-gen

 

 

 

模拟执行:

 

 

 

语法检测:

 

 

提交:

 

 

可能需要认证一下:

 

 

推送:

 

 

 

进入网页并刷新,出现‘v1’版本:

 

 

 

点击查看:

 

 

 

加入Jenkins

 

 

 

 

 

 

 

添加url地址:

 

 

 

 

 

 

 

构建:

 

 

 

出现错误不用紧张,点击查看:

 

 

根据原因排错:

这里是Jenkins没有权限连接到用户主机,修改文件:

 

 

 

更改运行用户:

 

 

重启Jenkins

——#systemctl restart jenkins

 

再次构建:

 

 

又爆红:

 

 

点击查看原因:

 

 

原因:此路径不存在,说明/var/www/html文件未创建过(一般是没有下过appach的主机),所以创建文件路径:

 

 

 再次构建:

 

 

 

变蓝,表示成功。

测试主机是否成功部署nginx

 

 

五.可以在gitlab远程添加web服务主机的网站信息:                                       

 

 

 

 

接着在Jenkins网站上立即构建,等待变蓝;再次进入服务主机nginx的网站上,查看是否添加成功。

有时候未添加成功,是因为2台机器的时间未同步,做一下时间同步:

 

 

Guess you like

Origin www.cnblogs.com/feige2L/p/11081765.html