标签:本地配置 str gen pos php echo 环境 系统 tmp
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 -> 钩选后直接安装
在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
开发机和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: 12, done. remote: Compressing objects: 100% (7/7), done. remote: Total 12 (delta 1), reused 0 (delta 0) Receiving objects: 100% (12/12), done. Resolving deltas: 100% (1/1), done.
# LNMP环境版本:nginx/1.8.1、PHP 5.5.30、MariaDB-5.5.64、wordpress-4.7.4 # tar xf wordpress-4.7.4-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
# 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解析 } }
# mkdir -p /data/html/www.leon.com # mkdir /data/backup # cat /etc/nginx/conf.d/www.leon.com.conf server { listen 80; 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
8.1 创建pipeline的任务并进行配置
8.2 进行构建
默认master分支,无需修改
可以点击查看部署日志
可以自行生成checkout流水线等语法
Jenkins + pipeline + Git + PHP (九)
标签:本地配置 str gen pos php echo 环境 系统 tmp
原文地址:https://www.cnblogs.com/cyleon/p/11913088.html