官方参考:https://jenkins.io/doc/book/pipeline/
官方语法参考:https://jenkins.io/doc/book/pipeline/syntax/
脚本:
pipeline {
agent any
environment {
def ITEMNAME = "erp"
def DESTPATH = "/home/ops/testpipe"
def codePATH="/var/lib/jenkins/workspace/test_pipeline"
}
stages {
stage('代码拉取'){
steps {
echo "checkout from ${ITEMNAME}"
git url: ' [email protected]***.cn:fangxin-tech/erp.git', branch: 'master'
}
}
stage('目录检查') {
steps {
echo "检查${DESTPATH}目录是否存在"
script{
def resultUpdateshell = sh script: 'ls ${DESTPATH}'
if (resultUpdateshell == 0) {
skip = '0'
return
}
}
}
}
stage('服务检查') {
steps {
echo "检查nginx进程是否存在"
script{
def resultUpdateshell = sh script: 'ps aux|grep nginx|grep -v grep'
if (resultUpdateshell == 0) {
skip = '0'
return
}
}
}
}
stage('supserver检查') {
steps {
echo "检查supserver是否存活"
script{
def resultUpdateshell = sh script: 'ps -ef |grep supervisor|grep -v grep'
if (resultUpdateshell == 0) {
skip = '0'
return
}
}
}
}
stage('发布确认') {
steps {
input "检查完成,是否发布?"
}
}
stage('代码推送') {
steps {
echo "code sync"
sh "cp ${codePATH}/* ${DESTPATH}/ -fr"
}
}
stage('gulp检查') {
steps {
echo "编译css和js文件"
script{
// def resultUpdateshell1 = sh script: 'cp -fr /home/ops/erp/node_modules ${DESTPATH}/'
// def resultUpdateshell2 = sh script: 'cp -fr /home/ops/erp/.env ${DESTPATH}/'
def resultUpdateshell3 = sh script: 'cd ${DESTPATH} && composer install'
def resultUpdateshell4 = sh script: 'cd ${DESTPATH} && /home/ops/testpipe/node_modules/.bin/gulp'
def resultUpdateshell5 = sh script: 'cd ${DESTPATH} && php artisan migrate'
def resultUpdateshell6 = sh script: 'cd ${DESTPATH} && php artisan queue:restart'
}
}
}
}
}
原文地址:http://blog.51cto.com/9025736/2061668