jenkins使用pipeline部署maven项目(简单版)

直接使用shell命令打包、上传、部署,流水线脚本如下:

前置步骤:

  1. jenkins的全局工具配置中配置安装maven,name为M3,后面pipeline脚本中需要用到,如图:
    在这里插入图片描述

  2. 在jenkins的Manage Credentials种创建个gitee的凭据gitee_user,如图:
    在这里插入图片描述

  3. 为了把jar包传到服务器上,要配置两台服务器的免密登录,参考如下连接:
    https://blog.csdn.net/u013415591/article/details/81943189

然后就是流水线任务中的代码:

pipeline {
    agent any

    tools {
        // Install the Maven version configured as "M3" and add it to the path.
        maven "M3"
    }

    stages {
        stage('Build') {
            steps {
                // Get some code from a GitHub repository
                git credentialsId: 'gitee_user', url: 'https://gitee.com/gitee_project.git'

                // Run Maven on a Unix agent.
                sh "mvn -Dmaven.test.failure.ignore=true clean package"
               
                sh 'scp $WORKSPACE/child_project/target/xxx.jar root@ip:/jar_dir_path/'
                sh 'ssh root@ip "/script_path/deploy.sh"'

            }

            post {
                // If Maven was able to run the tests, even if some of the test
                // failed, record the test results and archive the jar file.
                success {
                    archiveArtifacts 'child_project/target/*.jar'
                }
            }
        }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值