zoukankan      html  css  js  c++  java
  • 信步漫谈之Jenkins—集成环境搭建

    一、环境准备

    1)Jenkins 部署 WAR 包:jenkins.war(2.164.2 版本,WAR 包官方下载路径:https://jenkins.io/download/)
    2)Tomcat 服务器:apache-tomcat-7.0.94-windows-x64.zip(使用 Jdk1.8,要注意的是高版本的 jenkins 需要 jdk8才能运行)
    3)其他:SVN服务器,部署环境为联网状态(为联网安装 Jenkins 插件)
    jenkins 提供有各平台的部署安装包,本文使用 WAR 包部署 Jenkins,因为建虚拟机太麻烦了 -_-

    二、Tomcat 服务器配置

    1、打开 TOMCAT_HOME/conf/tomcat-users.xml 文件,添加用户配置如下

    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
    <role rolename="manager-jmx"/>
    <role rolename="manager-status"/>
    <user username="tomcat_user" password="123456"
    roles="manager-gui,manager-script,manager-jmx,manager-status" />

    2、打开 TOMCAT_HOME/conf/server.xml 文件,修改 URL 地址的编码解码字符集如下

    <Connector port="8080" protocol="HTTP/1.1"
    	connectionTimeout="20000"
    	redirectPort="8443" URIEncoding="UTF-8"/>

    3、打开 TOMCAT_HOME/bin/setclasspath.bat,在文件首部添加本地 JDK 的环境变量(指向本地安装的 Jdk1.8)

    set JAVA_HOME=C:Program FilesJavajdk1.8.0_121
    set JRE_HOME=C:Program FilesJavajre1.8.0_121

    4、将 Jenkins.war 放在 TOMCAT_HOME/webapps 目录下
    5、执行 TOMCAT_HOME/bin/startup.bat,启动 Tomcat

    三、Jenkins 主程序安装配置

    1、浏览器访问(访问网址示例:http://192.168.1.5:8080/jenkins),显示解锁界面,将指向的文件内容复制到输入框,“继续” 即可(这里填入的密文同时也是 admin 账号的密码)

    clipboard

    2、选择 “安装推荐的插件”,等待安装完成即可

    clipboard

    3、安装完成后,选择 “使用 admin 账户继续”,即可登录 Jenkins,效果图如下

    clipboard

    4、点击 “系统管理”->“全局安全配置”,开放用户注册(避免忘记密码情况),开放用户权限(学习 Jenkins 时使用)

    clipboard[13]

    5、点击 “系统管理”->“全局工具配置”,修改 settings 文件、jdk、maven 配置(其中名称 Name 随意) ,完成

    clipboard[15]

    image 

    四、集成测试

    1、创建 maven 项目

    image_thumb7[1]

    package com.alfred.java.jenkins.integration.demo01;
    
    public class HelloWorld {
    
    	private String name = "alfred";
    
    	public String sayHello() {
    		return "Hello world " + name;
    	}
    
    }
    HelloWorld.java
    <%@page import="com.alfred.java.jenkins.integration.demo01.HelloWorld"%>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    	<%=new HelloWorld().sayHello() %>
    </body>
    </html>
    index.jsp
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>com.alfred.java.jenkins</groupId>
    	<artifactId>jenkins-integration-demo01</artifactId>
    	<version>1.0.0-SNAPSHOT</version>
    	<packaging>war</packaging>
    	<dependencies>
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>javax.servlet-api</artifactId>
    			<version>3.0.1</version>
    			<scope>provided</scope>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet.jsp</groupId>
    			<artifactId>jsp-api</artifactId>
    			<version>2.2</version>
    			<scope>provided</scope>
    		</dependency>
    	</dependencies>
    	<profiles>
    		<profile>
    			<id>jdk-1.8</id>
    			<!-- 另外一种激活方式 -->
    			<activation>
    				<activeByDefault>true</activeByDefault>
    				<jdk>1.8</jdk>
    			</activation>
    			<properties>
    				<maven.compiler.source>1.8</maven.compiler.source>
    				<maven.compiler.target>1.8</maven.compiler.target>
    				<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    			</properties>
    		</profile>
    	</profiles>
    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.apache.tomcat.maven</groupId>
    				<artifactId>tomcat7-maven-plugin</artifactId>
    				<version>2.2</version>
    			</plugin>
    			<plugin>
    				<artifactId>maven-war-plugin</artifactId>
    				<version>2.2</version>
    				<configuration>
    					<!--如果想在没有web.xml文件的情况下构建WAR,请设置为false。 -->
    					<failOnMissingWebXml>false</failOnMissingWebXml>
    				</configuration>
    			</plugin>
    		</plugins>
    	</build>
    </project>
    pom.xml

    2、测试项目提交到 SVN 版本库
    3、使用 Jenkins 打包项目,创建一个新任务

    1555857878(1)

    4、创建一个自由风格的软件项目

    image

    5、配置软件的构建参数(源码地址、构建的 maven 指令)

    image

    image

    image

    6、执行立即构建,可以点击下方的构建记录,查看控制台输出的具体构建信息

    image

    image

    7、完成构建后,可在系统的用户目录下的 .jenkinsworkspace 文件夹找到构建的项目,进入项目 target 目录,可看到打包好的 WAR 包(C:UsersAdministrator.jenkinsworkspace)
    8、将 WAR 包部署到tomcat中,运行访问成功

    image

  • 相关阅读:
    ArcGIS for Android地图控件的5大常见操作
    adb开启不了解决方案
    Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤
    解决 Your project contains error(s),please fix them before running your application问题
    二路归并算法实现
    字符串全排列
    python连接MySQL
    .net常考面试题
    win7 web开发遇到的问题-由于权限不足而无法读取配置文件,无法访问请求的页面
    int.Parse()与int.TryParse()
  • 原文地址:https://www.cnblogs.com/alfredinchange/p/10742881.html
Copyright © 2011-2022 走看看