Jenkins+SVN+Maven+Docekr自動化部署流程搭建(一)
目的:
公司團隊研發,在產品敏捷開發過程有利於保證產品的可迭代性,QC缺陷的及時管控和保證開發人員注重業務編碼,以此來提高開發效率。將開發過程產品化,自動化,大大減少後期整合出現不可預料的問題。
環境說明:
1.需要inux系統虛機一臺(此案例我將使用ubuntu 16.04.3版本)
一、搭建Jenkins:
安裝步驟:
1.進入linux虛機,切換至root使用者。
[email protected]:~$ su root
Password:
[email protected]:/home/acs#
2.檢查此虛機是否已安裝Docker軟體。(如果出現下面:Client/Server,則已成功安裝Docker)
[email protected]:/home/acs# docker version
Client:
Version: 17.03.2-ce
API version: 1.27
Go version: go1.6.2
Git commit: f5ec1e2
Built: Thu Jul 5 23:07:48 2018
OS/Arch: linux/amd64
Server:
Version: 17.03.2-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.6.2
Git commit: f5ec1e2
Built: Thu Jul 5 23:07:48 2018
OS/Arch: linux/amd64
Experimental: false
[email protected]:/home/acs#
3.通過pull命令,在docker中央倉庫拉去映象。(具體映象可以在docker hub 官網查詢:https://hub.docker.com/)
docker pull jenkins
4.檢視docekr images 是否已將jenkins images拉取到本地。
[email protected]:/home/acs# docker images REPOSITORY TAG IMAGE ID CREATED SIZE jenkins latest cd14cecfdb3a 7 weeks ago 696 MB
5.執行docker run 命令,將images生成一個CONTAINER(容器)。
docker run --name my-jenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home jenkins
docker 指令:
--name <container_name>:設定生成容器的名字
-p <new:old>:new代表一個虛擬埠來對映old埠。
-v [local_file]:<docker_file>:提供一個虛機和docker之間一個掛載位置。
show console:
[email protected]:/etc$ sudo docker run --name jenkins-test -p 8081:8080 -p 50001:50000 -v /var/jenkins_home jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Sep 14, 2018 6:56:02 AM Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war
Sep 14, 2018 6:56:02 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Logging initialized @571ms
Sep 14, 2018 6:56:02 AM winstone.Logger logInternal
INFO: Beginning extraction from war file
Sep 14, 2018 6:56:04 AM org.eclipse.jetty.util.log.JavaUtilLog warn
WARNING: Empty contextPath
Sep 14, 2018 6:56:04 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: jetty-9.2.z-SNAPSHOT
Sep 14, 2018 6:56:05 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
Sep 14, 2018 6:56:06 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started [email protected]{/,file:/var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
Sep 14, 2018 6:56:06 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started [email protected]{HTTP/1.1}{0.0.0.0:8080}
Sep 14, 2018 6:56:06 AM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started @4283ms
Sep 14, 2018 6:56:06 AM winstone.Logger logInternal
INFO: Winstone Servlet Engine v2.0 running: controlPort=disabled
Sep 14, 2018 6:56:07 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Sep 14, 2018 6:56:07 AM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins
Sep 14, 2018 6:56:09 AM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Sep 14, 2018 6:56:09 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Sep 14, 2018 6:56:09 AM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Sep 14, 2018 6:56:10 AM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Sep 14, 2018 6:56:10 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Started Download metadata
Sep 14, 2018 6:56:10 AM jenkins.util.groovy.GroovyHookScript execute
INFO: Executing /var/jenkins_home/init.groovy.d/tcp-slave-agent-port.groovy
Sep 14, 2018 6:56:11 AM jenkins.InitReactorRunner$1 onAttained
INFO: Completed initialization
Sep 14, 2018 6:56:11 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.[email protected]2980dfd2: display name [Root WebApplicationContext]; startup date [Fri Sep 14 06:56:11 UTC 2018]; root of context hierarchy
Sep 14, 2018 6:56:11 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.[email protected]2980dfd2]: org.s[email protected]7ba0512c
Sep 14, 2018 6:56:11 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]7ba0512c: defining beans [authenticationManager]; root of factory hierarchy
Sep 14, 2018 6:56:12 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.[email protected]2a9e4890: display name [Root WebApplicationContext]; startup date [Fri Sep 14 06:56:12 UTC 2018]; root of context hierarchy
Sep 14, 2018 6:56:12 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.[email protected]2a9e4890]: org.s[email protected]23bfbc2d
Sep 14, 2018 6:56:12 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]23bfbc2d: defining beans [filter,legacy]; root of factory hierarchy
Sep 14, 2018 6:56:12 AM jenkins.install.SetupWizard init
INFO:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
ab4c622a463d4584929ace9a9158fab4
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
Sep 14, 2018 6:56:18 AM hudson.model.UpdateSite updateData
INFO: Obtained the latest update center data file for UpdateSource default
Sep 14, 2018 6:56:19 AM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
--> setting agent port for jnlp
--> setting agent port for jnlp... done
Sep 14, 2018 6:56:21 AM hudson.model.DownloadService$Downloadable load
INFO: Obtained the updated data file for hudson.tools.JDKInstaller
Sep 14, 2018 6:56:21 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Finished Download metadata. 11,421 ms
Sep 14, 2018 6:56:42 AM hudson.model.UpdateSite updateData
INFO: Obtained the latest update center data file for UpdateSource default
Sep 14, 2018 6:56:42 AM hudson.WebAppMain$3 run
INFO: Jenkins is fully up and running
6.執行docker ps 檢視正在執行的docker容器。
[email protected]:/home/acs# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a87bc3c15d04 jenkins "/bin/tini -- /usr..." 1 days ago Up 7 hours 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp my-jenkins
7.訪問jenkins地址:ip:port
a).通過下面指令進入jenkins docker 容器:
sudo docker exec -it my-jenkins /bin/bash
b).檢視init admin password(密碼是隨機生成的,你們的密碼和我是不一樣的)
[email protected]:/$ cat /var/jenkins_home/secrets/initialAdminPassword
.ab4c622a463d4584929ace9a9158fab4
c).將取到的密碼貼上值下面欄位
d).選擇安裝jenkins 外掛
e).And I choose install suggested plugins
f).Create init user and save finish
g).Open the road to jenkins
h).Successfully entered the Jenkins page.
8.配置jenkins環境變數
a).JDK(本案例使用jdk linux版本:1.8.0.131)
b).Maven(本案例maven linux版本:3.5.4)