---
title: "windows下用JENKINS做自动部署"
author: "lvjun106"
date: "2013-05-11T11:01:12Z"
tags: []
categories: ["研发管理"]
slug: "windows-jenkins"
draft: false
lastmod: "2013-05-11T11:01:12Z"
id: 1867118
url: "https://lvjun106.iteye.com/blog/1867118"
---

一. 安装JENKINS

    第一种是直接在[http://jenkins-ci.org/](http://jenkins-ci.org/) 页面上下载jenkins for windows 的安装包. 下载好了之后安装即可.

    第二种是下载jenkins的war包, 用java命令执行war包, 如java -jar jenkins.war

          运行时可以在后面添加一些参数,例如-httpPort=8082等等,这种情况就是防止端口被占用, 具体的参数列表如下

 

Command Line Parameter Description --httpPort=$HTTP\_PORT Runs Jenkins listener on port $HTTP\_PORT using standard *http* protocol. The default is port 8080. To disable (because you're using *https*), use port `-1`. --httpListenAddress=$HTTP\_HOST Binds Jenkins to the IP address represented by $HTTP\_HOST. The default is 0.0.0.0 — i.e. listening on all available interfaces.   
For example, to only listen for requests from localhost, you could use: --httpListenAddress=127.0.0.1 --httpsPort=$HTTP\_PORT Uses HTTPS protocol on port $HTTP\_PORT --httpsListenAddress=$HTTPS\_HOST Binds Jenkins to listen for HTTPS requests on the IP address represented by $HTTPS\_HOST. --ajp13Port=$AJP\_PORT Runs Jenkins listener on port $AJP\_PORT using standard *AJP13* protocol. The default is port 8009. To disable (because you're using *https*), use port `-1`. --ajp13ListenAddress=$AJP\_HOST Binds Jenkins to the IP address represented by $AJP\_HOST. The default is 0.0.0.0 — i.e. listening on all available interfaces. --argumentsRealm.passwd.$ADMIN\_USER Sets the password for user $ADMIN\_USER. If Jenkins security is turned on, you must log in as the $ADMIN\_USER in order to configure Jenkins or a Jenkins project. NOTE: You must also specify that this user has an *admin* role. (See next argument below). --argumentsRealm.roles.$ADMIN\_USER=admin Sets that $ADMIN\_USER is an administrative user and can configure Jenkins if Jenkins' security is turned on. See[Securing Jenkins](https://wiki.jenkins-ci.org/display/JENKINS/Securing+Jenkins "Securing Jenkins") for more information. -Xdebug -Xrunjdwp:transport=dt\_socket,address=$DEBUG\_PORT,server=y,suspend=n Sets debugging on and you can access debug on $DEBUG\_PORT. -logfile=$LOG\_PATH/winstone\_\`date +"%Y%m-%d\_%H-%M"\`.log Logging to desired file -XX:PermSize=512M -XX:MaxPermSize=2048M -Xmn128M -Xms1024M -Xmx2048M referring [to these options for Oracle Java](http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html) 

 

   运行完了之后,进入jenkins系统: http://&lt;hostname&gt;:你的端口号(默认8080)/

   选择菜单左边的管理JENKINS(Manage Jenkins), 找到安装windows服务(install as windows service)

   ![](https://wiki.jenkins-ci.org/download/attachments/3604487/jenkins-manage-menu.png?version=2&modificationDate=1296752210000)

  

  之后选择安装路径, 接下来的事就是可以去喝杯水,等着安装成功吧.

 

二.配置JENKINS

    在之前先安装几个插件. deploy plugin. (GIT plugin) optional

    安装插件的方法: 系统管理-&gt;插件管理-&gt;可选插件, 在里面找到所需要的,下接点安装就好了

 

    1. 建立一个job, 一般都是选择maven 项目. 如果你的项目没有用maven管理, 我还是建议你用吧.

    2. 进去第二个页面后, 在这里就要设置源代码管理工具, svn,git(用git之前要为jenkins装一个git 的plugin)等, 设置好你的源代码路径,设置好你的credential(用户名,密码), ssh key

    3. 设置job schedule, 点击页面上POLL SCM就显示出输入框,在里面输入你的计划. 例如我的是H/30 * * * *  每半小时查询一下是否有更新,如果有就开始构建.

    4. 自动构建的设置就已经完成了, 构建完的目标文件会存在$JENKINS\_HOME$\\jobs\\$your\_job\_name$\\workspace\\target\\ 这里.

    5. 如果需要自动部署的话,还需要配置一下. 在构建后操作那里, 选中deploy war/ear, 文件路径要选报相对路径,例如target/test.war, Context path里面填写你的项目名称, 之后再输入服务器的用户名密码等.如果用tomcat的话,需要用户具有manager-secret权限.之后再写上服务器URL

 

至此所有的配置就完成了.你可以试试构建一次