Jenkins
Note
Jenkins 为了保证构建环境的清洁,默认会在构建任务结束后,自动杀死(Kill)所有由该构建过程启动的衍生进程
使用 JENKINS_NODE_COOKIE 变量 JENKINS_NODE_COOKIE=dontKillMe nohup sh start_sps_ledger.sh > start.log 2>&1 &
接收文件
pipeline {
agent { label 'node12' }
parameters {
stashedFile(name: 'FILE') // 👈 关键修改
}
stages {
stage('copy file') {
steps {
// 恢复上传的文件
unstash 'FILE'
sh '''
echo "当前目录:"
ls -l
echo "重命名文件"
mv FILE front.zip
'''
}
}
stage('upload file') {
steps {
sh '''
scp -P 22222 front.zip xxx@xxx:/home/shingi/soft/test.zip
'''
}
}
}
}
定义变量
添加 script块:因为使用了变量定义 def DEPLOY_MODULE_DIR,需要在 script块中
stage('upload to os') {
steps {
script {
def DEPLOY_MODULE_DIR = "${env.PROJECT_DIR}/${params.MODULE_NAME}"
echo "😊开始上传 ${DEPLOY_MODULE_DIR}/Dockerfile"
dir("${DEPLOY_MODULE_DIR}") {
bat "scp Dockerfile ubuntu@soft.shingi:/home/ubuntu/build/"
}
}
}
}
pipeline {
agent {
label 'saq' // ⚠️ 替换为你的本地 Agent 的 label
}
environment {
PROJECT_DIR = 'C:/Users/hushun/Desktop/omni-portal-frontend'
// DEPLOY_DIR = '/usr/local/work_info'
DEPLOY_DIR = '/home/shingi/cs/'
}
stages {
stage('本地打包') {
steps {
dir("${env.PROJECT_DIR}") {
powershell """
Compress-Archive -Path "${env.PROJECT_DIR}\\dist" -DestinationPath "${env.PROJECT_DIR}\\dist.zip" -Force
"""
}
}
}
}
}
定义参数
pipeline {
agent any
parameters {
string(name: 'BRANCH', defaultValue: 'main', description: 'Git 分支名')
booleanParam(name: 'DEPLOY', defaultValue: true, description: '是否执行部署')
choice(name: 'ENV', choices: ['dev', 'test', 'prod'], description: '部署环境')
text(name: 'NOTES', defaultValue: '', description: '发布说明')
}
stages {
stage('Example') {
steps {
echo "分支: ${params.BRANCH}"
echo "部署环境: ${params.ENV}"
echo "是否部署: ${params.DEPLOY}"
echo "发布说明: ${params.NOTES}"
}
}
}
stage('InApp 部署') {
when {
expression { params.ENV == 'inapp' }
}
agent { label 'xx' }
steps {
echo "📤 删除历史..."
}
}