最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Jenkins+Git+Maven自動化部署配置詳解

 更新時間:2023年01月09日 10:03:21   作者:別團等shy哥發(fā)育  
本文主要介紹了Jenkins+Git+Maven自動化部署配置詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

基本思路

服務器配置如下:

192.168.159.50 gitlab服務器(Gitlab,內存至少5個G,要不根本跑不動)

192.168.159.51 jenkins服務器(Jenkins-Server+Maven+JDK)

192.168.158.52 測試服務器(JDK)

1、jenkins安裝maven依賴

image-20230107174445281

image-20230107174432629

2、git安裝

git安裝

這里先在jenkins這臺機器上裝個git

yum install -y git

image-20230107175826820

3、Jenkins中新建任務

新建一個任務,這里選擇構建一個maven項目

image-20230107174543897

項目名稱寫first

image-20230107174603376

3.1 git配置

image-20230107174705545

輸入項目地址(就是我們在自己gitlab服務器上的項目地址)

image-20230107180355689

選擇分支,看你的是master分支還是main分支

image-20230107180526759

3.2 maven配置

這里寫你jenkins服務器上的maven安裝位置:我的是/usr/local/maven

image-20230107180845359

3.3 pom.xml配置

代碼倉庫中pom.xml的位置

image-20230107182015492

這里還要看你pom.xml文件的位置,如果不是直接暴露在倉庫最外層,比如在demo目錄下,那就要寫成demo/pom.xml

3.4 build

點擊構建按鈕

image-20230107210906999

查看控制臺輸出:

image-20230107210033005

看到如下頁面說明打包完成了。

image-20230107205137340

Dashboard這里也可以看到成功了,并且顯示出了曾經(jīng)成功和失敗的時間

image-20230107210504969

去jenkins服務器上面查看是否打包成功,如下,可以看到target目錄和jar包說明打包成功了

image-20230107205216694

運行jar包測試一下

java -jar demo-0.0.1-SNAPSHOT.jar --server.port=8888

image-20230107205314375

這個只是個測試項目,只有一個負責測試的Controller,結構大概如下

image-20230107211031304

測試下簡單的業(yè)務類,訪問:http://192.168.159.51:8888/index/hello

image-20230107210350535

簡單業(yè)務類的測試也沒有任何的問題。這樣一個簡單的自動化部署就完成了,但是我們還想自動把jar包傳到測試服務器(192.168.159.52)上面執(zhí)行,而不是我們去手動執(zhí)行jar包。

4、自動化發(fā)布到測試服務器并自動執(zhí)行(Test-server)

4.1 安裝Publish Over SSH插件

先在jenkins服務器上安裝個插件:Publish Over SSH

image-20230107212220556

選中,點擊Install without restart

image-20230107212301949

4.2 修改Post Steps配置

image-20230107214419334

1、由于還沒有添加測試服務器,先去System Configuration中配置

image-20230107214542507

2、在Configure System菜單里 往下拉,找到Publish over SSH

image-20230107214605456

3、添加一臺目標服務器:這里我的測試服務器IP是192.168.159.52

4、測試下鏈接是否正常,左下角顯示Success說明連接沒問題

image-20230108192905445

5、再去看Post Steps中,選擇Send files or execute commands over SSH

這里就可以看到我們剛才添加的testserver了,如下圖所示。

image-20230108193352059

6、發(fā)布到遠程服務器的配置

image-20230108201037944

這樣讓遠程測試服務器上的jar包以后臺進程方式啟動

4.3 執(zhí)行構建

image-20230108201449189

查看控制臺輸出

image-20230108201506507

查看jar包是否傳到了測試服務器上,如下圖。

image-20230108201903673

查看測試服務器是否執(zhí)行了啟動jar包的腳本(腳本就是我們在Post Steps配置的那一行)

jps

image-20230108201600380

可以看到,jar包已經(jīng)被執(zhí)行了。

驗證業(yè)務類是否可訪問,192.168.159.52:8888/index/hello

image-20230108201657871

好了,到此我們已經(jīng)了解了持續(xù)集成和持續(xù)部署的基本操作,當然,這些還都是皮毛,后面再研究下。

5、小插曲

5.1 構建的時候報錯找不到jdk

默認yum安裝java的時候會顯示安裝的是openjdk1.8,實則實際上只安裝了jre

yum install -y java-devel

image-20230107202714630

5.2 阿里云鏡像配置

修改/usr/local/maven/conf/settings.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>${user.home}/.m2/repository</localRepository>
  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
    <pluginGroup>org.mortbay.jetty</pluginGroup>
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     | 
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are 
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    
    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
    <server>
        <id>releases</id>
        <username>ali</username>
        <password>ali</password>
      </server>
      <server>
        <id>Snapshots</id>
        <username>ali</username>
        <password>ali</password>
      </server>
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf> 
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>
    <mirror>
      <!--This is used to direct the public snapshots repo in the 
          profile below over to a different nexus group -->
      <id>nexus-public-snapshots</id>
      <mirrorOf>public-snapshots</mirrorOf> 
      <url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
    </mirror>
    <mirror>
      <!--This is used to direct the public snapshots repo in the 
          profile below over to a different nexus group -->
      <id>nexus-public-snapshots1</id>
      <mirrorOf>public-snapshots1</mirrorOf> 
      <url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
    </mirror>
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
   <profiles> 
    <profile>
      <id>development</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
          <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
          <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
    <profile>
      <!--this profile will allow snapshots to be searched when activated-->
      <id>public-snapshots</id>
      <repositories>
        <repository>
          <id>public-snapshots</id>
          <url>http://public-snapshots</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>public-snapshots</id>
          <url>http://public-snapshots</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
 
   <activeProfiles>
    <activeProfile>development</activeProfile>
    <activeProfile>public-snapshots</activeProfile>
   </activeProfiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

5.3 配置testserver之后構建異常

Exception when publishing, exception message [Exec timed out or was interrupted after 120,001 ms]

參考了其他大佬的文章,需要勾選Exec in pty選項

image-20230108201300736

然后重新構建就成功了

image-20230108201343290

 到此這篇關于Jenkins+Git+Maven自動化部署配置詳解的文章就介紹到這了,更多相關Jenkins Git Maven自動化部署內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

祁门县| 固安县| 平安县| 太湖县| 冀州市| 新巴尔虎右旗| 赣州市| 海门市| 锡林浩特市| 崇文区| 来安县| 库尔勒市| 宁波市| 闵行区| 齐齐哈尔市| 巴林右旗| 沧州市| 揭东县| 朔州市| 合山市| 磐石市| 稻城县| 澄城县| 湖南省| 南涧| 商水县| 辽阳县| 东宁县| 宿迁市| 综艺| 清丰县| 聂拉木县| 乳山市| 会宁县| 桐柏县| 耿马| 金华市| 酉阳| 临沭县| 连州市| 福泉市|