一、准备环境介绍

192.168.5.71    # gitlab 仓库IP
192.168.5.72 # 开发环境,用于提交代码等
192.168.5.150 # www.leon.com 运行wordpress的网站地址
192.168.5.239 # jenkins 服务器

二、Jenkins需要先安装pipeline插件

Jenkins -> 系统管理 -> 插件管理 -> 可选插件 -> 过滤pipeline -> 钩选后直接安装

三、创建两个git仓库,用于存放jenkinsfile脚本及php线上代码

在192.168.5.71上面使用git用户,也可以用root用户。

# 初始化一个仓库用于存储jenkins pipeline 的SCM脚本,jenkinsfile名称可修改成别的名字
# su - git
$ mkdir -p /home/git/repo/jenkinsfile/
$ cd repo/jenkinsfile/
$ git --bare init
Initialized empty Git repository in /home/git/repo/jenkinsfile/
-----------------------------------------------------------------------------
# 初始化之后的仓库地址是:git@192.168.5.71:/home/git/repo/jenkinsfile # 初始化第二个git仓库,用于上线wordpress代码
$ mkdir -p /home/git/repo/wordpress
$ cd /home/git/repo/wordpress/
$ git --bare init
Initialized empty Git repository in /home/git/repo/wordpress/
------------------------------------------------------------------------------
# 初始化之后的仓库地址是:git@192.168.5.71:/home/git/repo/wordpress

四、开发机(72)和LNMP环境的web机器(150)配置对git服务器(71)免密钥认证

开发机和web机在两台机器上面都要进行操作
LNMP环境安装可参见:https://www.cnblogs.com/cyleon/p/10110060.html
# 在两台(72、150)机器上面做如下操作
# ssh-keygen -t rsa -P '' -f ~/.ssh/id_dsa
# ssh-copy-id -i /root/.ssh/id_dsa.pub git@192.168.5.71 # 完成后测试是否能免密码拉取代码
# git clone git@192.168.5.71:/home/git/repo/jenkinsfile
Cloning into 'jenkinsfile'...
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta )
Receiving objects: % (/), done.
Resolving deltas: % (/), done.

五、在开发机(72)下载wordpress代码,并push到wordpress仓库中

# LNMP环境版本:nginx/1.8.、PHP 5.5.、MariaDB-5.5.、wordpress-4.7.
# tar xf wordpress-4.7.-zh_CN.tar.gz
# cd wordpress/
# cp wp-config-sample.php wp-config.php
# echo "OK" > status.html
# git init
# git remote add origin git@192.168.5.71:/home/git/repo/wordpress
# git add .
# git commit -m 'wordpress all files'
# git push origin master

六、编写jenkinsfile脚本文件

php代码发布不需要重启服务,如果是多台机器发布到一台机器之后再使用rsync进行同步。

# git clone git@192.168.5.71:/home/git/repo/jenkinsfile
# cd jenkinsfile/
# mkdir team-a/
# cd team-a/
# cat jenkinsfile-php
node ("wordpress-192.168.5.150") { # 指定jenkins的slave节点,也是WEB服务器
stage('git checkout') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'ccf5f140-9a28-49d6-abc8-40bc6c750323', url: 'git@192.168.5.71:/home/git/repo/wordpress']]])
}
stage('copy code') {
sh ''' rm -rf ${WORKSPACE}/.git
mv /data/html/www.leon.com /data/backup/www.leon.com-$(date +%F_%T)
cp -rf ${WORKSPACE} /data/html/www.leon.com '''
}
stage('check web test'){
sh "curl http://www.leon.com/status.html" # 需要在150本地配置/etc/hosts解析
}
}

七、nginx域名配置及hosts文件修改

# mkdir -p /data/html/www.leon.com
# mkdir /data/backup
# cat /etc/nginx/conf.d/www.leon.com.conf
server {
listen ;
server_name www.leon.com;
access_log /var/log/nginx/access.log main;
location / {
root /data/html/www.leon.com;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php$is_args$args;
} location ~ \.php {
root /data/html/www.leon.com;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
}
# nginx -s reload
# echo '192.168.5.150 www.leon.com' >> /etc/hosts

八、配置jenkins pipeline

8.1 创建pipeline的任务并进行配置

 8.2 进行构建

默认master分支,无需修改

可以点击查看部署日志

九、pipeline语法

可以自行生成checkout流水线等语法

Jenkins + pipeline + Git + PHP (九)的更多相关文章

  1. 持续集成高级篇之Jenkins Pipeline git拉取

    系列目录 PipeLine中拉取远程git仓库 前面讲自由式任务的时候,我们可以看到通过自由式job里提供的图形界面配置git拉取非常方便的,实际上使用PipeLine也并不复杂.这一节我们展示一下如 ...

  2. Jenkins + Pipeline + Git + Maven (十)

    一.准备环境介绍 192.168.5.71 # gitlab 仓库IP 192.168.5.72 # 开发环境,用于提交代码等 192.168.5.73 # tomcat 部署solo服务站点 192 ...

  3. 在容器中运行 Jenkins pipeline 任务

    持续集成中的 pipeline 技术和 docker 都是当前正在发展的主流方向,当然把它们结合起来在 CI/CD 过程中发挥出更强大的威力也是大家共同的目标.本文将介绍如何在 Jenkins pip ...

  4. 基于Jenkins Pipeline的ASP.NET Core持续集成实践

    最近在公司实践持续集成,使用到了Jenkins的Pipeline来提高团队基于ASP.NET Core API服务的集成与部署效率,因此这里总结一下. 一.关于持续集成与Jenkins Pipelin ...

  5. Jenkins pipeline job 根据参数动态获取触发事件的分支

    此文需要有Jenkins pipeline job 的简单使用经验 场景 我们日常的测试函数, 一般是不能仅仅在本地跑的,还需要一个公共的跑测试的环境,作为合并新的PR的依据. 如果用Jenkins ...

  6. Jenkins pipeline:pipeline 使用之语法详解

    一.引言 Jenkins 2.0的到来,pipline进入了视野,jenkins2.0的核心特性. 也是最适合持续交付的feature. 简单的来说,就是把Jenkins1.0版本中,Project中 ...

  7. [持续交付实践] Jenkins Pipeline 高可用设计方法

    前言 这篇写好一段时间了,一直也没发布上来,今天稍微整理下了交下作业,部分内容偷懒引用了一些别人的内容.使用Jenkins做持续集成/持续交付,当业务达到一定规模的时候,Jenkins本身就很容易成为 ...

  8. Jenkins Pipeline高级用法-ShareLibrary

    1.Github配置 1.1 上传jenkinsfile到github https://github.com/zeyangli/ShareLibrary-jenkins.git 2.Jenkins配置 ...

  9. Jenkins pipeline shared library

    Jenkinsfile https://jenkins.io/doc/book/pipeline/jenkinsfile/ Jenkins Pipeline is a suite of plugins ...

随机推荐

  1. CF1010D Mars rover

    CF1010D Mars rover 洛谷评测传送门 题目描述 Natasha travels around Mars in the Mars rover. But suddenly it broke ...

  2. Vue 使用lodash库减少watch对后台请求压力

    lodash需要新引入 我使用的是npm方式 使用lodash的_.debounce方法 具体代码: <!doctype html> <html lang="en" ...

  3. c语言新知

    C语言学得有点懈怠,昨个遇一个高手. 教了我两天,真细腻. 第一天,让我写一个程序删除字符串多余空格. 我俩代码对比   结果很显然了.

  4. bootstrap-editable 中关于onEditableSave 回调

    问题描述 在对bootstrap-editable 进行编辑时,有两种使用方法:一种直接在每一个column中进行编辑保存,例如:{ title:'标题', field:'title', width: ...

  5. 剑指offer:数据流中的中位数(小顶堆+大顶堆)

    1. 题目描述 /** 如何得到一个数据流中的中位数? 如果从数据流中读出奇数个数值,那么中位数就是所有数值排序之后位于中间的数值. 如果从数据流中读出偶数个数值,那么中位数就是所有数值排序之后中间两 ...

  6. 1+x 证书 Web 前端开发 MySQL 知识点梳理

    官方QQ群 1+x 证书 Web 前端开发 MySQL 知识点梳理 http://blog.zh66.club/index.php/archives/199/

  7. LeetCode20——有效的括号

    在记事本中写算法题和在纸上写其实感觉差不多,反正是不能进行调试.想起某高手的话,写代码要做到“人机合一”,写高级语言时(指的是 C 和 C++)脑海中要知道当前写的代码对应的反汇编代码,也就是要深入了 ...

  8. LCM Walk HDU - 5584

    A frog has just learned some number theory, and can't wait to show his ability to his girlfriend. No ...

  9. go中interface空指针不为nil判断方法

    interface空指针不为nil 当把一个空指针对象赋值给一个interface后,再判断!= nil就不再成立了 代码如下 package main import "fmt" ...

  10. Spring整合Mybaits java.sql.SQLException: Access denied for user '***'@'localhost' (using password: YES)

    最近在搞Spring和Mybatis的整合,当我们在Spring里面配置数据源,而数据源是从外部的properties文件读取过来的时候就会报错 java.sql.SQLException: Acce ...