配置项目
添加凭据
- 脚本配置
pipeline {
agent any
stages {
stage('pull code') {
steps {
git credentialsId: 'test' , url: 'https://gitee.com/ha1228322088/tomcat-java-demo.git'
sh 'mvn clean package'
sh 'mv target/ly-simple-tomcat-0.0.1-SNAPSHOT.war test.war'
sh 'scp test.war root@192.168.149.137:/usr/local/tomcat/webapps/'
sh 'ssh root@192.168.149.137 "/usr/local/tomcat/bin/catalina.sh stop"'
sh 'ssh root@192.168.149.137 "/usr/local/tomcat/bin/catalina.sh start"'
}
}
}
}
测试
含义jenkins的主机
[root@host ~]# yum -y install git
[root@host ~]# yum -y install maven
只含有tomcat的主机
[root@host2 ~]# yum -y install git
- 做免密登录
[root@host ~]# ssh root@192.168.149.137
登录过去后,退出
[root@host ~]# ssh-keygen
生成公钥和密码
[root@host ~]# ssh-copy-id 192.168.149.137
将公钥传输过去,免密完成