start.sh
serverName=jenkins
docker stop ${serverName}
#docker start ${serverName}
# jenkins更新版本后 不能rm 删除,否则会还原成最初安装样子
docker rm -f ${serverName}
docker run -u root --privileged=true --restart=always --name ${serverName} -d -p 10240:8080 -p 10241:50000 -v $PWD/maven:/usr/local/maven -v /usr/java:/usr/java -v /var/run/docker.sock:/var/run/docker.sock -v $PWD/jenkins/jenkins:/home/jenkins -v $PWD/jenkins/jenkins_home:/var/jenkins_home -v /usr/local/bin/docker-compose:/usr/local/bin/docker-compose -v /root/.ssh:/root/.ssh -v /etc/localtime:/etc/localtime jenkins/jenkins:jdk11
jdk放在/usr/java下面
maven放在/home/yjx/utools/jenkinsmaven/maven下面
下载插件 SSH Pipeline Steps版本2.0.0, Git Parameter Plug-In版本0.9.18
pip流水线脚本
pipeline {
agent any
tools{
//maven配置名称
maven 'maven3.6.3'
//jdk8配置名称
jdk 'jdk8'
}
// 配置全局环境,指定变量名=变量值信息
environment{
//发包服务器ip
pushhost = '192.168.1.13'
//gitee凭证
credentialsIdgitee='yjxgitee'
//发包服务器 ssh凭证
credentialsId13root='13root'
//git url
giturl='https://gitee.com/yjx-show/yjx_service.git'
//打包的pom路径
sparseCheckoutPathsPath='wvp-pro'
//sparseCheckoutPathsPath='yjx-service/yjx-core/yjx-common-core'
//大打包后的名称
jarName='wvp-pro-2.3.1.jar'
//打包文件路径
workspacepath="${WORKSPACE}"
}
// 存放所有任务的合集
stages {
stage('基础参数') {
steps {
echo "发包服务器 pushhost:${pushhost}"
echo "分支 branch:${branch}"
echo "gitee凭证 credentialsIdgitee:${credentialsIdgitee}"
echo "发包服务器 ssh凭证 credentialsId13root:${credentialsId13root}"
echo "giturl:${giturl}"
echo "打包的pom路径 sparseCheckoutPathsPath:${sparseCheckoutPathsPath}"
echo "打包文件路径 workspacepath:${workspacepath}"
}
}
stage('拉取Git代码') {
steps {
echo '拉取Git代码'
checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: "${sparseCheckoutPathsPath}"]]]], userRemoteConfigs: [[credentialsId: "${credentialsIdgitee}", url: "${giturl}"]]])
}
}
stage('构建代码 打包') {
steps {
sh 'pwd'
sh 'mvn clean install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dgpg.skip=true -f "${workspacepath}/${sparseCheckoutPathsPath}/pom.xml"'
sh 'pwd'
}
}
stage('ssh发包') {
steps {
script {
def remote = [:]
remote.name = '13root'
remote.host = "${pushhost}"
remote.port = 1322
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: "${credentialsId13root}", passwordVariable: 'password', usernameVariable: 'username')]) {
remote.user = "${username}"
remote.password = "${password}"
}
sshCommand remote: remote, command: "pwd"
//sshRemove remote: remote, path: '/usr/share/nginx/html/demo/dist'
sshPut remote: remote, from: "${workspacepath}/${sparseCheckoutPathsPath}/target/${jarName}", into: '/home/yjx/utools/jenkinsmaven/jenkins/jars/yjx-service'
//sshPut remote: remote, from: "/var/jenkins_home/workspace/yjx-service-pip/yjx-service/yjx-core/yjx-common-core/target/yjx-common-core-1.0.0-SNAPSHOT.jar", into: '/home/yjx/utools/jenkinsmaven/jenkins/jars/yjx-service'
sshCommand remote: remote, command: "sh /home/yjx/utools/jenkinsmaven/jenkins/jars/yjx-service/start.sh"
sshCommand remote: remote, command: "exit"
}
}
}
}
}