提交 192178d9 作者: yueyang.lv

ci(jenkins): 添加Jenkinsfile

上级 42441209
pipeline {
agent any
environment {
_node_modules_cache_dir = "../${JOB_NAME}_cache/"
_node_modules_zip_name = "node_modules.tar.gz"
_cache_file = "${_node_modules_cache_dir}${_node_modules_zip_name}"
_wx_web_hook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=88740cdf-7e83-48b7-8049-3e4cb1ced1ff"
}
options {
buildDiscarder logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '7',
numToKeepStr: '15'
)
}
parameters {
booleanParam(defaultValue: false, name: 'UPDATE_CACHE', description: '是否更新缓存(初次创建流水线请勾选此选项)')
booleanParam(defaultValue: true, name: 'PRIVATE_BUILD', description: '使用私有部署方式打包')
string defaultValue: 'https://test-cc.kube.ucas', name: 'REMOTE_URL', trim: true, description: '租户模块远程地址(不要以“/”结尾)\ndev:https://test-cc.kube.ucas'
}
stages {
stage('加载缓存') {
when {
expression { params.UPDATE_CACHE == false }
}
steps {
sh "echo ${_cache_file}"
sh "tar -xvf ${_cache_file} -C ./"
}
}
stage('安装依赖') {
when {
expression { params.UPDATE_CACHE == true }
}
steps {
sh """
export CI=false
yarn --registry=https://registry.npmjs.org
if [ ! -d ${_node_modules_cache_dir} ]; then
echo "缓存目录不存在,创建"
mkdir -p ${_node_modules_cache_dir}
fi
echo "删除缓存文件"
rm -rf "${_cache_file}"
echo "压缩 node_modules"
tar -czf ${_node_modules_zip_name} node_modules
echo "移动到缓存文件夹"
mv ${_node_modules_zip_name} ${_node_modules_cache_dir}
"""
}
}
stage('打包(租户版)') {
when {
expression { params.PRIVATE_BUILD == false }
}
steps {
sh """
export CI=false
REMOTE_URL=${params.REMOTE_URL} npm run server_build
"""
}
}
stage('打包(私有部署)') {
when {
expression { params.PRIVATE_BUILD == true }
}
steps {
sh """
export CI=false
npm run server_build:private
"""
}
}
}
post {
success {
sh """
curl "${_wx_web_hook}" \
-H 'Content-Type: application/json' \
-d '{
"msgtype": "markdown",
"markdown": {
"content": "## ${JOB_NAME} 打包完成
>**分支**: ${BRANCH_NAME}
>**模块**: ${params.PACKAGE} \n[任务详情](${BUILD_URL})"
}
}'
"""
}
failure {
sh """
curl "${_wx_web_hook}" \
-H 'Content-Type: application/json' \
-d '{
"msgtype": "markdown",
"markdown": {
"content": "## ${JOB_NAME} 打包完成
>**分支**: ${BRANCH_NAME}
>**模块**: ${params.PACKAGE} \n[失败原因](${BUILD_URL}/console)"
}
}'
"""
}
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论