zoukankan      html  css  js  c++  java
  • github+maven+jenkins(spring boot项目自动化发布)

    一.安装jenkins

    1.下载jenkins稳定版本的war包(https://www.jenkins.io/download/)。 

     2.服务器安装jenkins

    [root@rancher1 jenkins]# useradd jenkins
    [root@rancher1 jenkins]# cd /home/jenkins/
    [root@rancher1 jenkins]# ls -lart
    total 12
    -rw-r--r--  1 jenkins jenkins 231 Apr 11  2018 .bashrc
    -rw-r--r--  1 jenkins jenkins 193 Apr 11  2018 .bash_profile
    -rw-r--r--  1 jenkins jenkins  18 Apr 11  2018 .bash_logout
    drwxr-xr-x  4 jenkins jenkins  39 Mar 20  2020 .mozilla
    drwxr-xr-x. 6 root    root     58 Oct 29 23:39 ..
    drwx------  3 jenkins jenkins  78 Oct 29 23:39 .
    [root@rancher1 jenkins]# 
    

    上传jdk安装包(https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html)及jenkins安装包

    [jenkins@rancher1 ~]$ ls -lrt
    total 251132
    -rw-r--r-- 1 root root  67399569 Oct 29 23:41 jenkins.war
    -rw-r--r-- 1 root root 189756259 Oct 29 23:41 jdk-8u161-linux-x64.tar.gz
    

    配置java环境变量

    [jenkins@rancher1 ~]$tar zxvf  jdk-8u161-linux-x64.tar.gz
    修改.bash_profile
    [jenkins@rancher1 ~]$ cat .bash_profile 
    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    	. ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/.local/bin:$HOME/bin
    
    export PATH
    export JAVA_HOME=/home/jenkins/jdk1.8.0_161
    export PATH=$JAVA_HOME/bin:$PATH
    加载环境变量 [jenkins@rancher1 ~]$ source .bash_profile
    [jenkins@rancher1 ~]$ java -version
    java version "1.8.0_161"
    Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
    

    启动jenkins,war默认起8080端口

    [jenkins@rancher1 ~]$ nohup java -jar jenkins.war &
    [1] 5548
    [jenkins@rancher1 ~]$ nohup: ignoring input and appending output to ‘nohup.out’
    

    google访问jenkins(http://192.168.56.140:8080/)

    copy管理员密码

    [jenkins@rancher1 ~]$ cat /home/jenkins/.jenkins/secrets/initialAdminPassword
    7a838bec2fd84cddb2ce1e7a639b66fe
    

    建议选择安装推荐插件

    安装必要的插件

     创建管理员用户

     

    修改插件更新地址(国内地址):系统管理-》插件管理-》高级

    https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

    安装git

    下载git(https://github.com/git/git)

    [jenkins@rancher1 ~]$ ls -lh
    total 76M
    -rw-r--r-- 1 jenkins jenkins  11M Oct 29 17:18 git-master.zip
    drwxr-xr-x 8 jenkins jenkins  255 Dec 20  2017 jdk1.8.0_161
    -rw-r--r-- 1 root    root     65M Oct 29 23:41 jenkins.war
    -rw------- 1 jenkins jenkins 116K Oct 30 15:42 nohup.out
    drwxr-xr-x 8 jenkins jenkins   90 Oct 30 01:42 share
    [jenkins@rancher1 ~]$ unzip git-master.zip
    [jenkins@rancher1 ~]$ cd git-master
    [jenkins@rancher1 git-master]$ make
    [jenkins@rancher1 git-master]$ make install
    

    查看git版本

    [jenkins@rancher1 ~]$ git --version
    git version 2.29.GIT
    

    安装maven

    maven下载(http://maven.apache.org/download.cgi)

    解压,设置环境变量即可

    tar zxvf apache-maven-3.6.3-bin.tar.gz

    #环境变量配置
    [jenkins@rancher1 ~]$ cat .bash_profile 
    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    	. ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/.local/bin:$HOME/bin
    
    export PATH
    export JAVA_HOME=/home/jenkins/jdk1.8.0_161
    export MAVEN_HOME=/home/jenkins/apache-maven-3.6.3
    export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
    [jenkins@rancher1 ~]$ source .bash_profile 
    查看maven版本
    [jenkins@rancher1 ~]$ mvn --version
    Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
    Maven home: /home/jenkins/apache-maven-3.6.3
    Java version: 1.8.0_161, vendor: Oracle Corporation, runtime: /home/jenkins/jdk1.8.0_161/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "5.5.10-1.el7.elrepo.x86_64", arch: "amd64", family: "unix"  

    修改maven镜像地址为国内镜像

    cd /home/jenkins/apache-maven-3.6.3/conf
    修改settings.xml文件
    <mirrors></mirrors>中间增加
    
        <mirror>
         <id>nexus-aliyun</id>
         <mirrorOf>central</mirrorOf>
         <name>Nexus aliyun</name>
         <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>
    

    jenkins安装Publish Over SSH插件,支持远程发布功能(插件安装完成后,重启才能生效)

    安装maven插件

    jenkins配置jdk,git,maven等信息

    系统管理-》全局工具配置

    配置ssh信息(远程发布的机器信息)

    系统管理-》系统配置

    配置完成后,点击test configuration测试。

    新建任务

    该任务的绝对地址是:/home/jenkins/.jenkins/workspace/ywgk/

    source file等于自动在前面加了/home/jenkins/.jenkins/workspace/ywgk/

    立即构建,查看日志。

    构建报错,因为oracle驱动是oracle原厂的,镜像仓库不能下载。

    [jenkins@rancher1 ojdbc14]$ pwd
    /home/jenkins/.m2/repository/com/oracle/ojdbc14

    手工上传oracle驱动,再次构建。

    访问平台

    远程机器start.sh脚本

    [app@exam ~]$ cat start.sh 
    #!/bin/bash
    ps -ef|grep java|grep ywgk|awk '{print $2}'|xargs kill 
    java -jar ywgk-0.0.1-SNAPSHOT.jar > ywgk.log &
    

      

  • 相关阅读:
    深入理解六边形架构
    boost::lockfree使用介绍
    分布式监控系统zipkin介绍
    深入理解std::chrono的时钟Clock
    arcgis地图空白原因收集
    VM16
    ubuntu16.04 搭建简单http代理服务器 TinyProxy
    git 提交:gnutls_handshake() failed: Error in the pull function
    scrapy-redis redis 认证
    python把html网页转成pdf文件
  • 原文地址:https://www.cnblogs.com/muzisanshi/p/13897164.html
Copyright © 2011-2022 走看看