官方文档:https://www.jenkins.io/doc/book/pipeline/syntax/
pipeline{
agent any
stages{
stage("pull code"){
steps{
git 'git@gitlab.lyx666.com:root/hello-world.git'
}
}
stage("sonar"){
steps{
sh '''/app/maven/bin/mvn clean verify sonar:sonar \\
-Dsonar.projectKey=myjava \\
-Dsonar.projectName=\'myjava\' \\
-Dsonar.host.url=http://10.0.0.8:9000 \\
-Dsonar.token=squ_88406562d452aa3c24cec0dcb6be0b0f97500b8c'''
}
}
stage("compile"){
input{
message "continue or not"
ok "yes"
}
steps{
sh '/app/maven/bin/mvn clean package'
}
}
stage("push"){
steps{
sh 'scp ${WORKSPACE}/target/hello-world-war-9.0.0.war root@172.16.1.7:/code'
}
}
stage("unzip and slink"){
steps{
sh 'ssh root@172.16.1.7 \'unzip /code/hello-world-war-9.0.0.war -d /code/hello-world-war-9.0.0\' '
sh 'ssh root@172.16.1.7 \' rm -f /usr/share/tomcat/webapps/ROOT \''
sh 'ssh root@172.16.1.7 \' ln -s /code/hello-world-war-9.0.0 /usr/share/tomcat/webapps/ROOT \''
}
}
stage("restart tomcat "){
steps{
sh ' ssh root@172.16.1.7 \'systemctl restart tomcat \''
}
}
}
}