jenkins使用心得

jenkins基本配置

  1. 下载jenkins.war包,地址https://jenkins.io/download/
  2. 放到tomcat相应目录,启动
  3. 在C:\Users\(当前用户目录).jenkins\secrets 找到初始密码
  4. 登录到jenkins应用界面
  5. 系统管理->系统设置中设置相应jdk和maven
    jenkins使用心得
    目录如需修改也在此
    jenkins使用心得
    Jenkins的配置好了,插件管理目录在 系统管理->插件管理
    需要有的插件:
    Maven Integration plugin、Deploy to container Plugin

    新增项目操作
    1.新建mave项目,如果没有这个选项,请下载Maven Integration plugin插件
    jenkins使用心得
    2.选中丢弃的构建
    jenkins使用心得
    3.选择参数化构建过程
    jenkins使用心得
    添加参数选择 Choices
    输入参数名 Choies填 clean dependency:copy-dependencies -DoutputDirectory=lib package install
    4.选择源码
    jenkins使用心得
    5.新增post步骤,此步将生成的代码复制到发布的项目位置
    jenkins使用心得
    Windows操作脚本:
    C:
    cd txxzc-jfr\target
    copy jfr.war D:\apiTestTomcat\apachetomcat85\webapps
    Linux操作脚本
    if test $(ps -ef | grep tomcat-7.0.57/conf/logging.pro |wc -l) -eq 1
    then
    echo “------------no running ,can’t shutdown------------”
    else
    echo $(ps -ef | grep tomcat-7.0.57/conf/logging.pro |wc -l)
    /usr/local/apache-tomcat-7.0.57/bin/shutdown.sh
    echo “------------tomcat shutdowning--------------”
    sleep 30
    if test $(ps -ef | grep tomcat-7.0.57/conf/logging.pro |wc -l) -eq 1
    then
    echo “------------no running ,can’t kill------------”
    else
    ps -ef|grep tomcat-7.0.57/conf/logging.pro |cut -c 9-15|xargs kill -s 9
    echo “------------tomcat killing--------------”
    fi
    fi
    jenkins使用心得
    第二种
    /usr/local/apache-maven-3.5.0/bin/mvn clean package
    pwd
    ps -ef | grep tomcat2 | grep -v grep | awk ‘{print $2}’ | xargs kill -9
    cd /usr/local/tomcat2/webapps/
    rm -rf gameoflife*
    cd /root/.jenkins/workspace/image/gameoflife-web/target/
    cp gameoflife.war /usr/local/tomcat2/webapps/
    cd /
    sleep 2s
    export BUILD_ID=dontKillMe
    sh /usr/local/tomcat2/bin/startup.sh

6.增加构建后操作,选择Deploy war/ear to a Container
jenkins使用心得
选择tomcat
jenkins使用心得
7.Tomcat配置
在conf文件夹的tomcat-users.xml文件中添加如下代码,给Tomcat配置用户名和密码,热部署必须要有用户名和密码