z-docs/Jenkinsfile
2024-04-21 12:38:27 +08:00

60 lines
2.4 KiB
Groovy
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pipeline {
agent any
tools {
nodejs 'node-v18.18.2' // 使用全局配置的Node.js工具
}
stages {
stage('Checkout') {
steps {
// 从Git仓库克隆项目
checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: '4a774ecd-6ae3-4e27-a5e6-e6488b93b28a', url: 'https://gitea.1216.top/lxy/z-docs.git']])
}
}
stage('Install Dependencies') {
steps {
// 使用配置的Node.js版本安装项目依赖
sh '''
npm config set registry https://registry.npmmirror.com/
npm install
'''
}
}
stage('Build') {
steps {
// 执行构建步骤,比如打包
sh 'npm run build' // 假设你的package.json中有一个名为build的脚本用于打包
}
}
stage('deploy') {
steps {
sshPublisher(publishers: [sshPublisherDesc(
configName: 'u-xg', // SSH服务器的配置名称
transfers: [sshTransfer(
cleanRemote: false,
execCommand: '''
// 这里可以添加在远程机器上执行的其他命令
cd /var/www
rm zhub-docs -rf
mv z-docs zhub-docs
''',
execTimeout: 120000,
flatten: false, // 是否将源文件扁平化到单个目录中
makeEmptyDirs: true, // 是否创建远程目录结构
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '/var/www/z-docs', // 远程机器上的目标目录
removePrefix: 'dist/', // 如果需要,从源文件名中移除的前缀
sourceFiles: 'dist/**' // 要传输的文件模式这里表示dist目录及其所有内容
)],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: true // 设置为true以获取更详细的日志输出
)])
}
}
}
}