• Jenkins与持续集成


    1、环境变量配置:

    JENKINS_HOME=/home/work/apphome/jenkins_home
    MAVEN_HOME=/home/work/apache-maven-3.3.9
    PATH=$MAVEN_HOME/bin:$PATH
    配置非root用户
    export JENKINS_HOME=/home/work/apphome/jenkins_home
    export MAVEN_HOME=/home/work/apache-maven-3.3.9
    export JAVA_HOME=/home/jdk1.8.0_144
    export PATH=$MAVEN_HOME/bin:$JAVA_HOME:$PATH
    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
    root用户

    配置验证:java -version;mvn -version

    maven下载地址:wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz

    2、下载最新Jenkins.war包linux命令:wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war

    3、jenkins启动:java -jar jenkins.war -httpPort=9000

        无论Jenkins.war放在哪个目录下,都会再当前用户的根目录下创建.jenkins目录。有空可以看下Jenkins目录结构(workspace存放所有项目的代码)

    4、进入后台页面拷贝管理员密码登录

    5、安装插件:SSH Agent 、Git、GitHub、GitLab(企业)、publish Over SSH、SSH

    6、Jenkins任务配置:http://192.168.66.26:8080/

      1、新建任务--deploy--》构建一个自由风格的软件项目(springboot应用程序,拉取代码编译打包,自动部署)

      2、源码管理--》Git--》增加用户名,配置git的用户名及密码--》添加git仓库地址--》选择分支

      3、构建--》Execule shell 

    //刷新配置文件,确保配置文件有效
    source /etc/profile
    //获取应用程序的pid
    pid=${ps x | grep "应用程序的jar包名称" | grep -v grep | awk '{print $1}'}
    
    //如果程序在运行,则杀掉
    if [ -n "$pid" ]; then
    kill -9 $pid
    fi
    
    //Jenkins运行目录是.kenkins/workspace/
    //下面就是拉取的代码
    //进入到项目目录
    cd 项目名
    //打包
    mvn clean package
    //进入到target目录
    cd target
    //Jenkins启动程序后会把程序杀死,如下命令改为不杀死
    BUILD_ID=dontKillMe
    //后台启动springboot应用程序
    nohup java -jar 上面打包好的jar包名 &
    View Code

      4、构建后操作--》Build other projects:在本次构建完触发哪个任务(此处填写后面需要执行的对应测试脚本的job),保存

      5、新建任务--test,git(测试脚本git地址)

      6、构建--》Execule shell

    source /etc/profile
    //或者是
    source /home/work/.bash_profile
    pwd
    cd 测试项目名称
    //直接编译,执行测试case
    mvn clean package
    View Code

      7、测试报告在线可查及管理

        修改6点构建的Execule shell:

    source /etc/profile
    pwd
    cd 测试项目
    mvn clean package
    //执行如下命令,返回构建任务的id号
    result=$(curl -s http://192.168.66.26:8080/job/测试的job名称/lastBuild/buildNumber --user jenkins用户名:密码)
    
    //记得部署Tomcat,然后修改server.xml的端口号,启动Tomcat
    //根据id号创建文件夹
    mkdir /home/apache-tomcat/webapps/ROOT/$result
    //将生成的报告移动到新建的目录下
    cp /root/.jenkins/workspace/项目名/test-output/index.html /home/apache-tomcat/webapps/ROOT/$result/index.html
    View Code
  • 相关阅读:
    安装Flume的时候出现File Channel transaction capacity cannot be greater than the capacity of the channel capacity -解决方案 摘自网络
    在linux中配置环境变量
    CentOS中安装JAVA环境
    怎么在linux 用nginx做代理 配置.net core
    Another app is currently holding the yum lock; waiting for it to exit.. yum被锁定无法使用
    jQueryUI modal dialog does not show close button (x) JQueryUI和BootStrap混用时候,右上角关闭按钮显示不出图标的解决办法
    C#中 如何处理 JSON中的特殊字符
    php面向对象精要(3)
    php面向对象精要(2)
    php面向对象精要(1)
  • 原文地址:https://www.cnblogs.com/wangkc/p/10852987.html
Copyright © 2020-2023  润新知