pipeline流水线及分布式流水线发布php项目

本文介绍了如何使用Jenkins Pipeline结合Git进行PHP项目的自动化部署。内容包括创建Pipeline项目,编写并生成Pipeline脚本,设置分布式构建,利用Git仓库进行版本控制,以及通过SSH方式在Web服务器上执行部署脚本。整个流程详细讲解了从下载PHP源码到构建、测试、发布到线上环境的全过程。
摘要由CSDN通过智能技术生成
创建一个基于pipeline流水线的项目

在这里插入图片描述
第一个选项是流水线脚本(不是shell脚本),右上角有一个脚本的范例
范例:
1:尝试自己写一个脚本
2:hello world脚本(里面是函数,输出的内容,里面的node就代表单台服务器的节点,然后输出了一句话)
3:maven脚本
第二个是脚本在别的地方你把它取回来

在这里插入图片描述

在这里插入图片描述

Pipeline脚本语法架构介绍
#Pipeline脚本语法架构
node ('slave节点名') {          #被操控的节点服务器
def 变量    #def可以进行变量声明
	stage('阶段名A'){     #流水线阶段一
		执行步骤A
		执行步骤B
		执行步骤C
	 }
	stage('阶段名B'){     #流水线阶段二
		执行步骤A
		执行步骤B
		执行步骤C
	 }
	stage('阶段名C'){     #流水线阶段三
		执行步骤A
		执行步骤B
		执行步骤C
		}
	}

添加项目git参数化构建

在流水线里面git参数化构建是不让用

在这里插入图片描述

利用Pipeline Syntax,编写Pipeline Script并构建

(1)进入Pipeline Syntax

通过脚本代码生成器,生成Pipeline脚本代码

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

将生成的代码复制到流水线脚本相应步骤的stage函数里

在这里插入图片描述

如果执行失败的话,可能时间不同步(时间间隔差的很多)

安装时间服务器

[root@localhost ~]# yum install -y ntpdate
/usr/sbin/ntpdate ntp1.aliyun.com		#	时间同步
/bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime		#覆盖成上海的时区
[root@localhost ~]# systemctl reload jenkins
然后平滑重启Jenkins服务

在这里插入图片描述

(1)从远程仓库下载pipeline script,并构建
[root@localhost ~]# su - git				#切换用户
Last login: Thu Dec 27 08:56:53 CST 2018 from 192.168.182.148 on pts/1
Last failed login: Thu Dec 27 17:21:45 CST 2018 from 192.168.182.148 on ssh:notty
There were 4 failed login attempts since the last successful login.
[git@localhost ~]$ pwd
/home/git
[git@localhost ~]$ cd /home/git/repos/			
[git@localhost repos]$ ls
app.git
[git@localhost repos]$ 
[git@localhost repos]$ pwd
/home/git/repos
[git@localhost repos]$ mkdir jenkinsfile			#创建存放pipeline脚本的仓库
[git@localhost repos]$ cd jenkinsfile/
[git@localhost jenkinsfile]$ git --bare init			#初始化仓库
Initialized empty Git repository in /home/git/repos/jenkinsfile/
(2)在Jenkins服务器上,往远程仓库提交一个pipeline脚本
[root@localhost test]# git clone git@192.168.182.149:/home/git/repos/jenkinsfile
Cloning into 'jenkinsfile'...
warning: You appear to have cloned an empty repository.
[root@localhost test]# ls
jenkinsfile
[root@localhost test]# cd jenkinsfile/
[root@localhost jenkinsfile]# mkdir itemA
[root@localhost jenkinsfile]# vim itemA/jenkinsfile

#将脚本推送到远程仓库的master分支
[root@localhost jenkinsfile]# git add *
[root@localhost jenkinsfile]# git commit -m "第一次提交"			
[master (root-commit) 39752f6] 第一次提交
 1 file changed, 19 insertions(+)
 create mode 100644 itemA/jenkinsfile
[root@localhost jenkinsfile]# git push -u origin master
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值