简介
使用jenkins部署时会读取项目中Jenkinsfile文件,文件配置不对会导致部署失败
文件内容
java
pipeline {
agent any
parameters {
string(name: 'project_name', defaultValue: 'xxx1', description: '项目jar名称')
string(name: 'version', defaultValue: 'xxx2', description: '部署环境')
string(name: 'user_name', defaultValue: 'xxx3', description: '操作系统登录名')
}
stages {
stage('构建') {
steps {
sh """
mvn clean install -U -Dmaven.test.skip=true -DprofileActive=${params.version}
"""
}
}
stage('发布') {
steps {
sh """
/root/killJar.sh ${params.version}/${params.project_name}/boot/${params.project_name}.jar
rm -rf /home/${params.user_name}/api/${params.project_name}-${params.version}-1.0.0.tar.gz
rm -rf /home/${params.user_name}/api/${params.version}
cp ./target/${params.project_name}-${params.version}-1.0.0.tar.gz /home/${params.user_name}/xxx
cd /home/${params.user_name}/api
mkdir ${params.version}
chown ${params.user_name}:${params.user_name} ${params.project_name}-${params.version}-1.0.0.tar.gz
tar -zxvf ${params.project_name}-${params.version}-1.0.0.tar.gz -C ${params.version}
cd ${params.version}
pwd
chown -R ${params.user_name}:${params.user_name} ${params.project_name}
su - ${params.user_name} -c /home/xxx/xxx/${params.version}/${params.project_name}/bin/startup.sh
"""
}
}
}
}