First, prepare the environment Introduction
192.168 . 5.71 # gitlab warehouse IP 192.168 . 5.72 # development environment, code, etc. for submission of 192.168 . 5.150 Website address # www.leon.com run wordpress of 192.168 . 5.239 # Jenkins server
Two, Jenkins need to install the plug-in pipeline
Jenkins -> Administration -> Plugin Manager -> Optional plug-ins -> Filter Pipeline -> After installed directly VGH
Third, create two git repository for storing jenkinsfile php scripts and codes online
Use git user 192.168.5.71 above, the user may use root.
SCM script # initialize a warehouse for the storage jenkins pipeline, jenkinsfile name can be modified to other name # Water - Go $ mkdir -p /home/git/repo/jenkinsfile/ $ cd repo/jenkinsfile/ $ git --bare init Initialized empty Git repository in /home/git/repo/jenkinsfile/ -------------------------------------------------- --------------------------- warehouse address after the initialization #: git @ 192.168 . 5.71 : / Home / git / repo / jenkinsfile # Git repository second initialization, the code used on the line wordpress $ mkdir -p /home/git/repo/wordpress $ cd /home/git/repo/wordpress/ $ git --bare init Initialized empty Git repository in /home/git/repo/wordpress/ -------------------------------------------------- ---------------------------- warehouse address after the initialization #: git @ 192.168 . 5.71 : / Home / git / repo / WordPress
Fourth, the development unit (72) and a web environment LNMP machine (150) git configuration server (71) Free-key authentication
Development machine and web machine two machines must be operated above
LNMP installation environment can be found in: https: //www.cnblogs.com/cyleon/p/10110060.html
# Two following operations (72,150) above the machine
# SSH-keygen -t RSA -P '' -f ~ /. SSH / id_dsa # ssh-copy-id -i /root/.ssh/id_dsa.pub git@192.168.5.71 # After test whether it can pull free password codes # 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.
Fifth, in the development unit (72) wordpress download code and push into the warehouse wordpress
# 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
Sixth, write a script file jenkinsfile
# 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 " ) {# Slave nodes specified jenkins, is WEB server stage('git checkout') { checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'ccf5f140-9a28-49d6-abc8-40bc6c750323', url: '[email protected]:/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 Test Web ' ) { SH " curl http://www.leon.com/status.html " # 150 in the local configuration needs to be parsed / etc / hosts } }
Seven, nginx domain configuration and modify the hosts file
# 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 $ on $ a / / 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
Eight, configuration jenkins pipeline
8.1 Creating pipeline tasks and configure
8.2 build
The default master branch without modification
Click to view the log can be deployed
Nine, pipeline grammar
Self checkout lines and the like may be generated grammar