jenkins配置以pipeline项目构建项目初体验
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jenkins配置以pipeline项目构建项目初体验相关的知识,希望对你有一定的参考价值。
官方参考: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'
}
}
}
}
}
以上是关于jenkins配置以pipeline项目构建项目初体验的主要内容,如果未能解决你的问题,请参考以下文章
Jenkins——Jenkins 构建Maven项目(三种风格的项目构建自由风格Maven风格Pipeline流水线风格)