jenkins发布项目

jenkins发布项目,第1张

jenkins发布项目 Jenkins发布项目 server192.168.200.145clien192.168.200.146 1.用Jenkins发布一个项目








pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                // Get some code from a GitHub repository
                git 'https://gitee.com/forgotten/tomcat-java-demo.git'

                // Run Maven on a Unix agent.
                sh '''
                    mvn -Dmaven.test.failure.ignore=true clean package
                    mv target/ly-simple-tomcat-0.0.1-SNAPSHOT.war target/myapp.war
                '''
                // To run Maven on a Windows agent, use
                // bat "mvn -Dmaven.test.failure.ignore=true clean package"
                
            }
        }
        stage("publish"){
            steps{
                sh '''
                    ssh root@192.168.200.146 'tar -Jcf /opt/backup/myapp-$(date +%Y%m%d).tar.xz /usr/local/tomcat/webapps/myapp'
                    scp target/myapp.war root@192.168.200.146:/usr/local/tomcat/webapps/
                    ssh root@192.168.200.146 '/usr/local/tomcat/bin/catalina.sh stop;sleep 3;/usr/local/tomcat/bin/catalina.sh start'
                '''
            }            
        }
    }
}

当git仓库有密码时


2.用命令拉取java项目
[root@RS2 ~]# yum -y install git
[root@RS2 ~]# git clone https://gitee.com/forgotten/tomcat-java-demo.git

//打包成war包
[root@RS2 ~]# cd tomcat-java-demo/
[root@RS2 tomcat-java-demo]# mvn package -Dmaven.test.skip=true
[root@RS2 tomcat-java-demo]# ls
db           Dockerfile   LICENSE  README.md  target
deploy.yaml  jenkinsfile  pom.xml  src
[root@RS2 tomcat-java-demo]# cd target/
[root@RS2 target]# ls
classes
generated-sources
ly-simple-tomcat-0.0.1-SNAPSHOT
ly-simple-tomcat-0.0.1-SNAPSHOT.war
maven-archiver
maven-status
[root@RS2 target]# mv ly-simple-tomcat-0.0.1-SNAPSHOT.war myapp.war

//备份原有的项目
[root@RS2 tomcat]# cp  -r webapps/ /opt/

//做免密登入 传输war包
[root@RS2 tomcat-java-demo]# ssh-keygen -t rsa 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:q1BABxB41Ywx0k2d/O2wLawVEAjS/CxNe/Uq0A1YP+M root@RS2
The key's randomart image is:
+---[RSA 3072]----+
| .=BBXo*oo       |
|. .+=oB *..      |
| .  .= o *+o     |
|    ..* o.=oo    |
|     ..oS.EB     |
|     .  ..* o    |
|    .   .+ .     |
|     . ..        |
|      .          |
+----[SHA256]-----+

[root@RS2 tomcat-java-demo]# ssh-copy-id root@192.168.200.146
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.146 (192.168.200.146)' can't be established.
ECDSA key fingerprint is SHA256:lHjJVpgxAHQML7Nzdt8CT4/1AZePELgM5EEUPTONw9A.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.200.146's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.200.146'"
and check to make sure that only the key(s) you wanted were added.

[root@RS2 target]# scp myapp.war root@192.168.200.146:/usr/local/tomcat/webapps/ 
myapp.war                100%   17MB 138.0MB/s   00:00 

[root@RS1 webapps]# ls
docs      host-manager  jenkins.war  myapp      ROOT
examples  jenkins       manager      myapp.war  test

//重启tomcat
[root@RS1 webapps]# /usr/local/tomcat/bin/catalina.sh restart 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4664694.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-06
下一篇 2022-11-06

发表评论

登录后才能评论

评论列表(0条)

保存