一、安装Maven
下载地址:https://maven.apache.org/download.cgi
把下载的安装包解压
tar -xvf apache-maven-3.6.-bin.tar.gz
配置环境变量
vim /etc/profile
export M2_HOME=/usr/local/maven/apache-maven-3.6.
export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
使配置文件生效
source /etc/profile
查看版本信息
mvn -v
二、jenkins配置
1、配置jdk
先在Jenkins服务器上安装jdk
进入Jenkins页面:Manage Jenkins->Global Tool Configuration
2、配置SVN凭据
进入Jenkins页面:Credentials
3、配置Maven
进入Jenkins页面:Manage Jenkins->Global Tool Configuration
进入Manage Jenkins->Configure System,配置全局环境变量
4、新建一个Pipeline的job
脚本:
pipeline {
agent any
environment { def sscs_ms_version = "SSCS.MS_V100R001B040" def iCommunity_Dir = "/JenkinsPackage/iCommunity/SSCS.MS/"
def iCommunity_WorkSpace_Dir = "/var/lib/jenkins/workspace/智慧社区_01.sscs.ms"
}
stages {
stage("检出智慧社区相关代码") {
steps {
echo "开始检出 SSCS_MS 代码"
checkout([$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[credentialsId: 'svn_readonly', #新建SVN凭据时填写的ID
depthOption: 'infinity',
ignoreExternalsOption: true,
local: 'SSCS_MS',
remote: "http://192.168.1.3/CoNET/view/trunk/sscp/sscs-ms"]],
workspaceUpdater: [$class: 'UpdateUpdater']])
echo "检出 SSCS_MS 成功"
}
} stage("构建智慧社区相关模块") {
tools{jdk "JDK1.8"}
steps {
echo "开始构建 SSCS_MS 模块"
dir('SSCS_MS') {
sh 'mvn -X package'
}
echo "构建 SSCS_MS 成功"
}
} stage("复制各个模块到指定目录") {
steps {
sh 'mkdir -p ${iCommunity_Dir}${BUILD_NUMBER}' sh 'mkdir -p ${iCommunity_Dir}${BUILD_NUMBER}/${sscs_ms_version}' dir('SSCS_MS/target') {
sh 'cp ${sscs_ms_version}.zip ${iCommunity_Dir}${BUILD_NUMBER}/${sscs_ms_version}/'
}
echo "sscs_ms的包移动成功!"
}
}
}
}