天天看點

jenkins實戰安裝java maven項目

一、建構配置搭建

1、建立一個新的項目,選擇maven來操作

2、要想建構maven項目,代碼庫中必須要有一個maven

3、把maven壓縮包,解壓到一個目錄,在目前目錄下使用git上傳到gitlab項目庫

1

2

3

4

5

<code>git init</code>

<code>git add .</code>

<code>git commit -m </code><code>"maven"</code>

<code>git remote add origin [email protected]:YH02</code><code>/java</code><code>.git</code>

<code>git push origin master</code>

4、在gitlab上面新建構一個項目(例子java)并上傳maven項目代碼

<a href="https://s5.51cto.com/wyfs02/M01/96/01/wKiom1kb83KzusYeAACgW1QU2wM178.png-wh_500x0-wm_3-wmp_4-s_1006171946.png" target="_blank"></a>

<a href="https://s2.51cto.com/wyfs02/M01/96/01/wKioL1kb9rLj8qDSAAB8BpQbOT0829.png-wh_500x0-wm_3-wmp_4-s_756381164.png" target="_blank"></a>

<a href="https://s2.51cto.com/wyfs02/M02/96/01/wKioL1kb9uSAUJ8qAABSstJDpR8438.png-wh_500x0-wm_3-wmp_4-s_2587339791.png" target="_blank"></a>

(1)maven可以在jenkin的系統設定裡面的全局工具設定選項裡面有manven安裝

(2)手動安裝maven

6

7

8

9

10

11

12

13

<code>apache-maven-3.3.9-bin.</code><code>tar</code><code>.gz</code><code># 把包上傳到jenkins伺服器</code>

<code> </code><code>[root@salt-node2 ~]</code><code># tar xf apache-maven-3.3.9-bin.tar.gz -C /data/</code>

<code> </code><code>[root@salt-node2 ~]</code><code># ll /data/</code>

<code>total 0</code>

<code>drwxr-xr-x 6 root root 92 May 14 21:40 apache-maven-3.3.9</code>

<code> </code><code>[root@salt-node2 ~]</code><code># export PATH=$PATH:/data/apache-maven-3.3.9/bin #增加環境變量,可以寫到bashrc裡面</code>

<code> </code><code>[root@salt-node2 ~]</code><code># mvn -v</code>

<code>Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)</code>

<code>Maven home: </code><code>/data/apache-maven-3</code><code>.3.9</code>

<code>Java version: 1.8.0_131, vendor: Oracle Corporation</code>

<code>Java home: </code><code>/usr/lib/jvm/java-1</code><code>.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64</code><code>/jre</code>

<code>Default locale: en_US, platform encoding: UTF-8</code>

<code>OS name: </code><code>"linux"</code><code>, version: </code><code>"3.10.0-327.el7.x86_64"</code><code>, arch: </code><code>"amd64"</code><code>, family: </code><code>"unix"</code>

(3)在jenkins裡面填入manve的安裝路徑

<a href="https://s5.51cto.com/wyfs02/M02/96/02/wKioL1kb-Q2RM3f0AACKxYPr2ss365.png-wh_500x0-wm_3-wmp_4-s_884159645.png" target="_blank"></a>

<a href="https://s4.51cto.com/wyfs02/M01/96/02/wKioL1kb-bGjtTuHAABL4y-qc48029.png-wh_500x0-wm_3-wmp_4-s_2245062765.png" target="_blank"></a>

5、SRC是核心檔案,pom檔案是開發提供

6、儲存 開始建構

報錯:

<a href="https://s3.51cto.com/wyfs02/M01/96/06/wKiom1kcCq-RkQioAAP8qGgjtTE320.png-wh_500x0-wm_3-wmp_4-s_811720341.png" target="_blank"></a>

maven庫不能連接配接,由于是國外的伺服器,這裡我們将配置成國内的伺服器

編輯maven的配置檔案

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

<code> </code><code>[root@salt-node2 ~]</code><code># cd /data/apache-maven-3.3.9/</code>

<code> </code><code>[root@salt-node2 </code><code>/data/apache-maven-3</code><code>.3.9]</code><code># cd conf/</code>

<code> </code><code>[root@salt-node2 </code><code>/data/apache-maven-3</code><code>.3.9</code><code>/conf</code><code>]</code><code># ll</code>

<code>total 16</code>

<code>drwxr-xr-x 2 root root    36 Nov 11  2015 logging</code>

<code>-rw-r--r-- 1 root root 10216 Nov 11  2015 settings.xml</code>

<code>-rw-r--r-- 1 root root  3649 Nov 11  2015 toolchains.xml</code>

<code> </code><code>[root@salt-node2 </code><code>/data/apache-maven-3</code><code>.3.9</code><code>/conf</code><code>]</code><code># cp settings.xml settings.xml.bak</code>

<code> </code><code>[root@salt-node2 </code><code>/data/apache-maven-3</code><code>.3.9</code><code>/conf</code><code>]</code><code># vim settings.xml</code>

<code>&lt;?xml version=</code><code>"1.0"</code> <code>encoding=</code><code>"UTF-8"</code><code>?&gt;</code>

<code>&lt;settings xmlns=</code><code>"http://maven.apache.org/SETTINGS/1.0.0"</code>

<code>          </code><code>xmlns:xsi=</code><code>"http://www.w3.org/2001/XMLSchema-instance"</code>

<code>          </code><code>xsi:schemaLocation=</code><code>"http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"</code><code>&gt;</code>

<code>&lt;mirrors&gt;</code>

<code> </code><code>&lt;mirror&gt;</code>

<code>            </code><code>&lt;</code><code>id</code><code>&gt;yxyc&lt;</code><code>/id</code><code>&gt;</code>

<code>            </code><code>&lt;mirrorOf&gt;*&lt;</code><code>/mirrorOf</code><code>&gt;</code>

<code>            </code><code>&lt;url&gt; </code><code>#鏡像庫 </code>

<code>        </code><code>&lt;</code><code>/mirror</code><code>&gt;</code>

<code>    </code><code>&lt;</code><code>/mirrors</code><code>&gt;</code>

<code>        </code><code>&lt;profiles&gt;</code>

<code>         </code><code>&lt;profile&gt;</code>

<code>            </code><code>&lt;</code><code>id</code><code>&gt;default&lt;</code><code>/id</code><code>&gt;</code>

<code>            </code><code>&lt;repositories&gt;</code>

<code>                </code><code>&lt;repository&gt;</code>

<code>                    </code><code>&lt;</code><code>id</code><code>&gt;public&lt;</code><code>/id</code><code>&gt;</code>

<code>                    </code><code>&lt;url&gt; </code><code>#本地庫 </code>

<code>                    </code><code>&lt;releases&gt;</code>

<code>                        </code><code>&lt;enabled&gt;</code><code>true</code><code>&lt;</code><code>/enabled</code><code>&gt;</code>

<code>                    </code><code>&lt;</code><code>/releases</code><code>&gt;</code>

檢視修改了那些東西

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

<code> </code><code>[root@salt-node2 </code><code>/data/apache-maven-3</code><code>.3.9</code><code>/conf</code><code>]</code><code># diff settings.xml settings.xml.bak </code>

<code>1a2,45</code>

<code>&gt; </code>

<code>&gt; &lt;!--</code>

<code>&gt; Licensed to the Apache Software Foundation (ASF) under one</code>

<code>&gt; or </code><code>more</code> <code>contributor license agreements.  See the NOTICE </code><code>file</code>

<code>&gt; distributed with this work </code><code>for</code> <code>additional information</code>

<code>&gt; regarding copyright ownership.  The ASF licenses this </code><code>file</code>

<code>&gt; to you under the Apache License, Version 2.0 (the</code>

<code>&gt; </code><code>"License"</code><code>); you may not use this </code><code>file</code> <code>except </code><code>in</code> <code>compliance</code>

<code>&gt; with the License.  You may obtain a copy of the License at</code>

<code>&gt;     http:</code><code>//www</code><code>.apache.org</code><code>/licenses/LICENSE-2</code><code>.0</code>

<code>&gt; Unless required by applicable law or agreed to </code><code>in</code> <code>writing,</code>

<code>&gt; software distributed under the License is distributed on an</code>

<code>&gt; </code><code>"AS IS"</code> <code>BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY</code>

<code>&gt; KIND, either express or implied.  See the License </code><code>for</code> <code>the</code>

<code>&gt; specific language governing permissions and limitations</code>

<code>&gt; under the License.</code>

<code>&gt; --&gt;</code>

<code>&gt;  | This is the configuration </code><code>file</code> <code>for</code> <code>Maven. It can be specified at two levels:</code>

<code>&gt;  |</code>

<code>&gt;  |  1. User Level. This settings.xml </code><code>file</code> <code>provides configuration </code><code>for</code> <code>a single user,</code>

<code>&gt;  |                 and is normally provided </code><code>in</code> <code>${user.home}/.m2</code><code>/settings</code><code>.xml.</code>

<code>&gt;  |                 NOTE: This location can be overridden with the CLI option:</code>

<code>&gt;  |                 -s </code><code>/path/to/user/settings</code><code>.xml</code>

<code>&gt;  |  2. Global Level. This settings.xml </code><code>file</code> <code>provides configuration </code><code>for</code> <code>all Maven</code>

<code>&gt;  |                 </code><code>users</code> <code>on a machine (assuming they're all using the same Maven</code>

<code>&gt;  |                 installation). It's normally provided </code><code>in</code>

<code>&gt;  |                 ${maven.home}</code><code>/conf/settings</code><code>.xml.</code>

<code>&gt;  |                 -gs </code><code>/path/to/global/settings</code><code>.xml</code>

<code>&gt;  | The sections </code><code>in</code> <code>this sample </code><code>file</code> <code>are intended to give you a running start at</code>

<code>&gt;  | getting the most out of your Maven installation. Where appropriate, the default</code>

<code>&gt;  | values (values used when the setting is not specified) are provided.</code>

<code>&gt;  |--&gt;</code>

<code>5,31c49,256</code>

<code>&lt; &lt;mirrors&gt;   </code>

<code>&lt;  &lt;mirror&gt;</code>

<code>&lt;             &lt;</code><code>id</code><code>&gt;baijia&lt;</code><code>/id</code><code>&gt;</code>

<code>&lt;             &lt;mirrorOf&gt;*&lt;</code><code>/mirrorOf</code><code>&gt;</code>

<code>&lt;             &lt;url&gt;http:</code><code>//maven</code><code>.aliyun.com</code><code>/nexus/content/groups/public</code><code>&lt;</code><code>/url</code><code>&gt;</code>

<code>&lt;         &lt;</code><code>/mirror</code><code>&gt;</code>

<code>&lt;     &lt;</code><code>/mirrors</code><code>&gt;</code>

<code>&lt;         &lt;profiles&gt;</code>

<code>&lt;    &lt;profile&gt;</code>

<code>&lt;             &lt;</code><code>id</code><code>&gt;default&lt;</code><code>/id</code><code>&gt;</code>

<code>&lt;             &lt;repositories&gt;</code>

<code>&lt;                 &lt;repository&gt;</code>

<code>&lt;                     &lt;</code><code>id</code><code>&gt;public&lt;</code><code>/id</code><code>&gt;</code>

<code>&lt;                     &lt;url&gt;http:</code><code>//maven</code><code>.aliyun.com</code><code>/nexus/content/groups/public</code><code>&lt;</code><code>/url</code><code>&gt;</code>

<code>&lt;                     &lt;releases&gt;</code>

<code>&lt;                         &lt;enabled&gt;</code><code>true</code><code>&lt;</code><code>/enabled</code><code>&gt;</code>

<code>&lt;                     &lt;</code><code>/releases</code><code>&gt;</code>

<code>&lt;                     &lt;snapshots&gt;</code>

<code>&lt;                     &lt;</code><code>/snapshots</code><code>&gt;</code>

<code>&lt;                 &lt;</code><code>/repository</code><code>&gt;</code>

<code>&lt;             &lt;</code><code>/repositories</code><code>&gt;</code>

<code>&lt;         &lt;</code><code>/profile</code><code>&gt;</code>

<code>&lt; &lt;</code><code>/profiles</code><code>&gt;</code>

<code>&lt;     &lt;activeProfiles&gt;</code>

<code>&lt;         &lt;activeProfile&gt;default&lt;</code><code>/activeProfile</code><code>&gt;</code>

<code>&lt;     &lt;</code><code>/activeProfiles</code><code>&gt;</code>

<code>---</code>

<code>&gt;   &lt;!-- localRepository</code>

<code>&gt;    | The path to the </code><code>local</code> <code>repository maven will use to store artifacts.</code>

<code>&gt;    |</code>

<code>&gt;    | Default: ${user.home}/.m2</code><code>/repository</code>

<code>&gt;   &lt;localRepository&gt;</code><code>/path/to/local/repo</code><code>&lt;</code><code>/localRepository</code><code>&gt;</code>

<code>&gt;   --&gt;</code>

<code>&gt;   &lt;!-- interactiveMode</code>

<code>&gt;    | This will determine whether maven prompts you when it needs input. If </code><code>set</code> <code>to </code><code>false</code><code>,</code>

<code>&gt;    | maven will use a sensible default value, perhaps based on some other setting, </code><code>for</code>

<code>&gt;    | the parameter </code><code>in</code> <code>question.</code>

<code>&gt;    | Default: </code><code>true</code>

<code>&gt;   &lt;interactiveMode&gt;</code><code>true</code><code>&lt;</code><code>/interactiveMode</code><code>&gt;</code>

<code>&gt;   &lt;!-- offline</code>

<code>&gt;    | Determines whether maven should attempt to connect to the network when executing a build.</code>

<code>&gt;    | This will have an effect on artifact downloads, artifact deployment, and others.</code>

<code>&gt;    | Default: </code><code>false</code>

<code>&gt;   &lt;offline&gt;</code><code>false</code><code>&lt;</code><code>/offline</code><code>&gt;</code>

<code>&gt;   &lt;!-- pluginGroups</code>

<code>&gt;    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.</code>

<code>&gt;    | when invoking a </code><code>command</code> <code>line like </code><code>"mvn prefix:goal"</code><code>. Maven will automatically add the group identifiers</code>

<code>&gt;    | </code><code>"org.apache.maven.plugins"</code> <code>and </code><code>"org.codehaus.mojo"</code> <code>if</code> <code>these are not already contained </code><code>in</code> <code>the list.</code>

<code>&gt;    |--&gt;</code>

<code>&gt;   &lt;pluginGroups&gt;</code>

<code>&gt;     &lt;!-- pluginGroup</code>

<code>&gt;      | Specifies a further group identifier to use </code><code>for</code> <code>plugin lookup.</code>

<code>&gt;     &lt;pluginGroup&gt;com.your.plugins&lt;</code><code>/pluginGroup</code><code>&gt;</code>

<code>&gt;     --&gt;</code>

<code>&gt;   &lt;</code><code>/pluginGroups</code><code>&gt;</code>

<code>&gt;   &lt;!-- proxies</code>

<code>&gt;    | This is a list of proxies </code><code>which</code> <code>can be used on this machine to connect to the network.</code>

<code>&gt;    | Unless otherwise specified (by system property or </code><code>command</code><code>-line switch), the first proxy</code>

<code>&gt;    | specification </code><code>in</code> <code>this list marked as active will be used.</code>

<code>&gt;   &lt;proxies&gt;</code>

<code>&gt;     &lt;!-- proxy</code>

<code>&gt;      | Specification </code><code>for</code> <code>one proxy, to be used </code><code>in</code> <code>connecting to the network.</code>

<code>&gt;      |</code>

<code>&gt;     &lt;proxy&gt;</code>

<code>&gt;       &lt;</code><code>id</code><code>&gt;optional&lt;</code><code>/id</code><code>&gt;</code>

<code>&gt;       &lt;active&gt;</code><code>true</code><code>&lt;</code><code>/active</code><code>&gt;</code>

<code>&gt;       &lt;protocol&gt;http&lt;</code><code>/protocol</code><code>&gt;</code>

<code>&gt;       &lt;username&gt;proxyuser&lt;</code><code>/username</code><code>&gt;</code>

<code>&gt;       &lt;password&gt;proxypass&lt;</code><code>/password</code><code>&gt;</code>

<code>&gt;       &lt;host&gt;proxy.host.net&lt;</code><code>/host</code><code>&gt;</code>

<code>&gt;       &lt;port&gt;80&lt;</code><code>/port</code><code>&gt;</code>

<code>&gt;       &lt;nonProxyHosts&gt;</code><code>local</code><code>.net|some.host.com&lt;</code><code>/nonProxyHosts</code><code>&gt;</code>

<code>&gt;     &lt;</code><code>/proxy</code><code>&gt;</code>

<code>&gt;   &lt;</code><code>/proxies</code><code>&gt;</code>

<code>&gt;   &lt;!-- servers</code>

<code>&gt;    | This is a list of authentication profiles, keyed by the server-</code><code>id</code> <code>used within the system.</code>

<code>&gt;    | Authentication profiles can be used whenever maven must </code><code>make</code> <code>a connection to a remote server.</code>

<code>&gt;   &lt;servers&gt;</code>

<code>&gt;     &lt;!-- server</code>

<code>&gt;      | Specifies the authentication information to use when connecting to a particular server, identified by</code>

<code>&gt;      | a unique name within the system (referred to by the </code><code>'id'</code> <code>attribute below).</code>

<code>&gt;      | NOTE: You should either specify username</code><code>/password</code> <code>OR privateKey</code><code>/passphrase</code><code>, since these pairings are</code>

<code>&gt;      |       used together.</code>

<code>&gt;     &lt;server&gt;</code>

<code>&gt;       &lt;</code><code>id</code><code>&gt;deploymentRepo&lt;</code><code>/id</code><code>&gt;</code>

<code>&gt;       &lt;username&gt;repouser&lt;</code><code>/username</code><code>&gt;</code>

<code>&gt;       &lt;password&gt;repopwd&lt;</code><code>/password</code><code>&gt;</code>

<code>&gt;     &lt;</code><code>/server</code><code>&gt;</code>

<code>&gt;     &lt;!-- Another sample, using keys to authenticate.</code>

<code>&gt;       &lt;</code><code>id</code><code>&gt;siteServer&lt;</code><code>/id</code><code>&gt;</code>

<code>&gt;       &lt;privateKey&gt;</code><code>/path/to/private/key</code><code>&lt;</code><code>/privateKey</code><code>&gt;</code>

<code>&gt;       &lt;passphrase&gt;optional; leave empty </code><code>if</code> <code>not used.&lt;</code><code>/passphrase</code><code>&gt;</code>

<code>&gt;   &lt;</code><code>/servers</code><code>&gt;</code>

<code>&gt;   &lt;!-- mirrors</code>

<code>&gt;    | This is a list of mirrors to be used </code><code>in</code> <code>downloading artifacts from remote repositories.</code>

<code>&gt;    | It works like this: a POM may </code><code>declare</code> <code>a repository to use </code><code>in</code> <code>resolving certain artifacts.</code>

<code>&gt;    | However, this repository may have problems with heavy traffic at </code><code>times</code><code>, so people have mirrored</code>

<code>&gt;    | it to several places.</code>

<code>&gt;    | That repository definition will have a unique </code><code>id</code><code>, so we can create a mirror reference </code><code>for</code> <code>that</code>

<code>&gt;    | repository, to be used as an alternate download site. The mirror site will be the preferred</code>

<code>&gt;    | server </code><code>for</code> <code>that repository.</code>

<code>&gt;   &lt;mirrors&gt;</code>

<code>&gt;     &lt;!-- mirror</code>

<code>&gt;      | Specifies a repository mirror site to use instead of a given repository. The repository that</code>

<code>&gt;      | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used</code>

<code>&gt;      | </code><code>for</code> <code>inheritance and direct lookup purposes, and must be unique across the </code><code>set</code> <code>of mirrors.</code>

<code>&gt;     &lt;mirror&gt;</code>

<code>&gt;       &lt;</code><code>id</code><code>&gt;mirrorId&lt;</code><code>/id</code><code>&gt;</code>

<code>&gt;       &lt;mirrorOf&gt;repositoryId&lt;</code><code>/mirrorOf</code><code>&gt;</code>

<code>&gt;       &lt;name&gt;Human Readable Name </code><code>for</code> <code>this Mirror.&lt;</code><code>/name</code><code>&gt;</code>

<code>&gt;       &lt;url&gt;http:</code><code>//my</code><code>.repository.com</code><code>/repo/path</code><code>&lt;</code><code>/url</code><code>&gt;</code>

<code>&gt;     &lt;</code><code>/mirror</code><code>&gt;</code>

<code>&gt;      --&gt;</code>

<code>&gt;   &lt;</code><code>/mirrors</code><code>&gt;</code>

<code>&gt;   &lt;!-- profiles</code>

<code>&gt;    | This is a list of profiles </code><code>which</code> <code>can be activated </code><code>in</code> <code>a variety of ways, and </code><code>which</code> <code>can modify</code>

<code>&gt;    | the build process. Profiles provided </code><code>in</code> <code>the settings.xml are intended to provide </code><code>local</code> <code>machine-</code>

<code>&gt;    | specific paths and repository locations </code><code>which</code> <code>allow the build to work </code><code>in</code> <code>the </code><code>local</code> <code>environment.</code>

<code>&gt;    | For example, </code><code>if</code> <code>you have an integration testing plugin - like cactus - that needs to know where</code>

<code>&gt;    | your Tomcat instance is installed, you can provide a variable here such that the variable is</code>

<code>&gt;    | dereferenced during the build process to configure the cactus plugin.</code>

<code>&gt;    | As noted above, profiles can be activated </code><code>in</code> <code>a variety of ways. One way - the activeProfiles</code>

<code>&gt;    | section of this document (settings.xml) - will be discussed later. Another way essentially</code>

<code>&gt;    | relies on the detection of a system property, either matching a particular value </code><code>for</code> <code>the property,</code>

<code>&gt;    | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a</code>

<code>&gt;    | value of </code><code>'1.4'</code> <code>might activate a profile when the build is executed on a JDK version of </code><code>'1.4.2_07'</code><code>.</code>

<code>&gt;    | Finally, the list of active profiles can be specified directly from the </code><code>command</code> <code>line.</code>

<code>&gt;    | NOTE: For profiles defined </code><code>in</code> <code>the settings.xml, you are restricted to specifying only artifact</code>

<code>&gt;    |       repositories, plugin repositories, and </code><code>free</code><code>-form properties to be used as configuration</code>

<code>&gt;    |       variables </code><code>for</code> <code>plugins </code><code>in</code> <code>the POM.</code>

<code>&gt;   &lt;profiles&gt;</code>

<code>&gt;     &lt;!-- profile</code>

<code>&gt;      | Specifies a </code><code>set</code> <code>of introductions to the build process, to be activated using one or </code><code>more</code> <code>of the</code>

<code>&gt;      | mechanisms described above. For inheritance purposes, and to activate profiles via &lt;activatedProfiles/&gt;</code>

<code>&gt;      | or the </code><code>command</code> <code>line, profiles have to have an ID that is unique.</code>

<code>&gt;      | An encouraged best practice </code><code>for</code> <code>profile identification is to use a consistent naming convention</code>

<code>&gt;      | </code><code>for</code> <code>profiles, such as </code><code>'env-dev'</code><code>, </code><code>'env-test'</code><code>, </code><code>'env-production'</code><code>, </code><code>'user-jdcasey'</code><code>, </code><code>'user-brett'</code><code>, etc.</code>

<code>&gt;      | This will </code><code>make</code> <code>it </code><code>more</code> <code>intuitive to understand what the </code><code>set</code> <code>of introduced profiles is attempting</code>

<code>&gt;      | to accomplish, particularly when you only have a list of profile </code><code>id</code><code>'s </code><code>for</code> <code>debug.</code>

<code>&gt;      | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.</code>

<code>&gt;     &lt;profile&gt;</code>

<code>&gt;       &lt;</code><code>id</code><code>&gt;jdk-1.4&lt;</code><code>/id</code><code>&gt;</code>

<code>&gt;       &lt;activation&gt;</code>

<code>&gt;         &lt;jdk&gt;1.4&lt;</code><code>/jdk</code><code>&gt;</code>

<code>&gt;       &lt;</code><code>/activation</code><code>&gt;</code>

<code>&gt;       &lt;repositories&gt;</code>

<code>&gt;         &lt;repository&gt;</code>

<code>&gt;           &lt;</code><code>id</code><code>&gt;jdk14&lt;</code><code>/id</code><code>&gt;</code>

<code>&gt;           &lt;name&gt;Repository </code><code>for</code> <code>JDK 1.4 builds&lt;</code><code>/name</code><code>&gt;</code>

<code>&gt;           &lt;url&gt;http:</code><code>//www</code><code>.myhost.com</code><code>/maven/jdk14</code><code>&lt;</code><code>/url</code><code>&gt;</code>

<code>&gt;           &lt;layout&gt;default&lt;</code><code>/layout</code><code>&gt;</code>

<code>&gt;           &lt;snapshotPolicy&gt;always&lt;</code><code>/snapshotPolicy</code><code>&gt;</code>

<code>&gt;         &lt;</code><code>/repository</code><code>&gt;</code>

<code>&gt;       &lt;</code><code>/repositories</code><code>&gt;</code>

<code>&gt;     &lt;</code><code>/profile</code><code>&gt;</code>

<code>&gt;     &lt;!--</code>

<code>&gt;      | Here is another profile, activated by the system property </code><code>'target-env'</code> <code>with a value of </code><code>'dev'</code><code>,</code>

<code>&gt;      | </code><code>which</code> <code>provides a specific path to the Tomcat instance. To use this, your plugin configuration</code>

<code>&gt;      | might hypothetically </code><code>look</code> <code>like:</code>

<code>&gt;      | ...</code>

<code>&gt;      | &lt;plugin&gt;</code>

<code>&gt;      |   &lt;groupId&gt;org.myco.myplugins&lt;</code><code>/groupId</code><code>&gt;</code>

<code>&gt;      |   &lt;artifactId&gt;myplugin&lt;</code><code>/artifactId</code><code>&gt;</code>

<code>&gt;      |   &lt;configuration&gt;</code>

<code>&gt;      |     &lt;tomcatLocation&gt;${tomcatPath}&lt;</code><code>/tomcatLocation</code><code>&gt;</code>

<code>&gt;      |   &lt;</code><code>/configuration</code><code>&gt;</code>

<code>&gt;      | &lt;</code><code>/plugin</code><code>&gt;</code>

<code>&gt;      | NOTE: If you just wanted to inject this configuration whenever someone </code><code>set</code> <code>'target-env'</code> <code>to</code>

<code>&gt;      |       anything, you could just leave off the &lt;value/&gt; inside the activation-property.</code>

<code>&gt;       &lt;</code><code>id</code><code>&gt;</code><code>env</code><code>-dev&lt;</code><code>/id</code><code>&gt;</code>

<code>&gt;         &lt;property&gt;</code>

<code>&gt;           &lt;name&gt;target-</code><code>env</code><code>&lt;</code><code>/name</code><code>&gt;</code>

<code>&gt;           &lt;value&gt;dev&lt;</code><code>/value</code><code>&gt;</code>

<code>&gt;         &lt;</code><code>/property</code><code>&gt;</code>

<code>&gt;       &lt;properties&gt;</code>

<code>&gt;         &lt;tomcatPath&gt;</code><code>/path/to/tomcat/instance</code><code>&lt;</code><code>/tomcatPath</code><code>&gt;</code>

<code>&gt;       &lt;</code><code>/properties</code><code>&gt;</code>

<code>&gt;   &lt;</code><code>/profiles</code><code>&gt;</code>

<code>&gt;   &lt;!-- activeProfiles</code>

<code>&gt;    | List of profiles that are active </code><code>for</code> <code>all builds.</code>

<code>&gt;   &lt;activeProfiles&gt;</code>

<code>&gt;     &lt;activeProfile&gt;alwaysActiveProfile&lt;</code><code>/activeProfile</code><code>&gt;</code>

<code>&gt;     &lt;activeProfile&gt;anotherAlwaysActiveProfile&lt;</code><code>/activeProfile</code><code>&gt;</code>

<code>&gt;   &lt;</code><code>/activeProfiles</code><code>&gt;</code>

二、部署

上面的建構完畢後,接下來是部署了。

我們要在java1上配置裡面,寫入新的内容,來完成建構完畢後,自動部署的功能!!!

<a href="https://s3.51cto.com/wyfs02/M01/96/07/wKiom1kcD4iyuoS4AABRI3UcMLo905.png-wh_500x0-wm_3-wmp_4-s_2671226201.png" target="_blank"></a>

jenkins 打包完畢後,檔案會生成到這個目錄

<code> </code><code>[root@salt-node2 ~]</code><code># cd /var/lib/jenkins/jobs/</code>

<code>java/       java1/      PHP/        php-deploy/ </code>

<code> </code><code>[root@salt-node2 ~]</code><code># cd /var/lib/jenkins/jobs/java1/</code>

<code>builds/          lastStable/      modules/         workspace/       </code>

<code>config.xml       lastSuccessful/  nextBuildNumber  </code>

<code> </code><code>[root@salt-node2 ~]</code><code># cd /var/lib/jenkins/jobs/java1/workspace/</code>

<code> </code><code>[root@salt-node2 </code><code>/var/lib/jenkins/jobs/java1/workspace</code><code>]</code><code># ll</code>

<code>total 8</code>

<code>-rw-r--r-- 1 root root 1574 May 14 22:13 pom.xml</code>

<code>drwxr-xr-x 4 root root   28 May 14 22:13 src</code>

<code>drwxr-xr-x 7 root root 4096 May 14 22:25 target</code>

<code> </code><code>[root@salt-node2 </code><code>/var/lib/jenkins/jobs/java1/workspace</code><code>]</code><code># cd target/</code>

<code> </code><code>[root@salt-node2 </code><code>/var/lib/jenkins/jobs/java1/workspace/target</code><code>]</code><code># ll</code>

<code>drwxr-xr-x 3 root root   16 May 14 22:23 classes</code>

<code>drwxr-xr-x 2 root root   27 May 14 22:24 maven-archiver</code>

<code>drwxr-xr-x 3 root root   34 May 14 22:23 maven-status</code>

<code>-rw-r--r-- 1 root root 2435 May 14 22:24 original-testweb-0.0.1-SNAPSHOT.jar</code>

<code>drwxr-xr-x 2 root root   79 May 14 22:23 surefire-reports</code>

<code>drwxr-xr-x 3 root root   16 May 14 22:23 </code><code>test</code><code>-classes</code>

<code>-rw-r--r-- 1 root root 2662 May 14 22:25 testweb-0.0.1-SNAPSHOT.jar</code>

三 maven下載下傳的jar包存放在那裡了

在家目錄下面有一個.m2檔案,下載下傳的jar包都會儲存在本地這裡

<code> </code><code>[root@salt-node2 ~]</code><code># cd .m2/</code>

<code> </code><code>[root@salt-node2 ~/.m2]</code><code># ll</code>

<code>total 4</code>

<code>drwxr-xr-x 13 root root 4096 May 14 22:24 repository</code>

<code> </code><code>[root@salt-node2 ~/.m2]</code><code># cd repository/</code>

<code> </code><code>[root@salt-node2 ~/.m2</code><code>/repository</code><code>]</code><code># ll</code>

<code>drwxr-xr-x 6 root root 66 May 14 22:24 asm</code>

<code>drwxr-xr-x 3 root root 37 May 14 22:21 backport-util-concurrent</code>

<code>drwxr-xr-x 3 root root 24 May 14 22:19 classworlds</code>

<code>drwxr-xr-x 4 root root 29 May 14 22:25 com</code>

<code>drwxr-xr-x 3 root root 24 May 14 22:19 commons-cli</code>

<code>drwxr-xr-x 3 root root 25 May 14 22:24 commons-lang</code>

<code>drwxr-xr-x 3 root root 32 May 14 22:21 commons-logging</code>

<code>drwxr-xr-x 3 root root 17 May 14 22:24 jdom</code>

<code>drwxr-xr-x 3 root root 18 May 14 22:18 junit</code>

<code>drwxr-xr-x 3 root root 18 May 14 22:21 log4j</code>

<code>drwxr-xr-x 6 root root 61 May 14 22:21 org</code>

本文轉自 kesungang 51CTO部落格,原文連結:http://blog.51cto.com/sgk2011/1926750,如需轉載請自行聯系原作者