欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Jenkins+Git+Maven自動(dòng)化部署配置詳解

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

基本思路

服務(wù)器配置如下:

192.168.159.50 gitlab服務(wù)器(Gitlab,內(nèi)存至少5個(gè)G,要不根本跑不動(dòng))

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

192.168.158.52 測試服務(wù)器(JDK)

1、jenkins安裝maven依賴

image-20230107174445281

image-20230107174432629

2、git安裝

git安裝

這里先在jenkins這臺(tái)機(jī)器上裝個(gè)git

yum install -y git

image-20230107175826820

3、Jenkins中新建任務(wù)

新建一個(gè)任務(wù),這里選擇構(gòu)建一個(gè)maven項(xiàng)目

image-20230107174543897

項(xiàng)目名稱寫first

image-20230107174603376

3.1 git配置

image-20230107174705545

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

image-20230107180355689

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

image-20230107180526759

3.2 maven配置

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

image-20230107180845359

3.3 pom.xml配置

代碼倉庫中pom.xml的位置

image-20230107182015492

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

3.4 build

點(diǎn)擊構(gòu)建按鈕

image-20230107210906999

查看控制臺(tái)輸出:

image-20230107210033005

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

image-20230107205137340

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

image-20230107210504969

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

image-20230107205216694

運(yùn)行jar包測試一下

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

image-20230107205314375

這個(gè)只是個(gè)測試項(xiàng)目,只有一個(gè)負(fù)責(zé)測試的Controller,結(jié)構(gòu)大概如下

image-20230107211031304

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

image-20230107210350535

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

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

4.1 安裝Publish Over SSH插件

先在jenkins服務(wù)器上安裝個(gè)插件:Publish Over SSH

image-20230107212220556

選中,點(diǎn)擊Install without restart

image-20230107212301949

4.2 修改Post Steps配置

image-20230107214419334

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

image-20230107214542507

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

image-20230107214605456

3、添加一臺(tái)目標(biāo)服務(wù)器:這里我的測試服務(wù)器IP是192.168.159.52

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

image-20230108192905445

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

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

image-20230108193352059

6、發(fā)布到遠(yuǎn)程服務(wù)器的配置

image-20230108201037944

這樣讓遠(yuǎn)程測試服務(wù)器上的jar包以后臺(tái)進(jìn)程方式啟動(dòng)

4.3 執(zhí)行構(gòu)建

image-20230108201449189

查看控制臺(tái)輸出

image-20230108201506507

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

image-20230108201903673

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

jps

image-20230108201600380

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

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

image-20230108201657871

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

5、小插曲

5.1 構(gòu)建的時(shí)候報(bào)錯(cuò)找不到j(luò)dk

默認(rèn)yum安裝java的時(shí)候會(huì)顯示安裝的是openjdk1.8,實(shí)則實(shí)際上只安裝了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之后構(gòu)建異常

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

參考了其他大佬的文章,需要勾選Exec in pty選項(xiàng)

image-20230108201300736

然后重新構(gòu)建就成功了

image-20230108201343290

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

相關(guān)文章

  • Java SpringMVC異常處理機(jī)制詳解

    Java SpringMVC異常處理機(jī)制詳解

    這篇文章主要介紹了springmvc如何進(jìn)行異常處理,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2021-09-09
  • Java線程池隊(duì)列LinkedTransferQueue示例詳解

    Java線程池隊(duì)列LinkedTransferQueue示例詳解

    這篇文章主要為大家介紹了Java線程池隊(duì)列LinkedTransferQueue示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Spring中@Autowired與@Resource的區(qū)別詳析

    Spring中@Autowired與@Resource的區(qū)別詳析

    @Autowired與@Resource都可以用來裝配bean,都可以寫在字段上,或?qū)懺趕etter方法上,下面這篇文章主要給大家介紹了關(guān)于Spring中@Autowired與@Resource區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2021-10-10
  • Java中的Null到底是什么

    Java中的Null到底是什么

    null是沒有地址,""是有地址但是里面的內(nèi)容是空的,好比做飯 null說明連鍋都沒有 而""則是有鍋沒米,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,下面我們來詳細(xì)學(xué)習(xí)一下它吧
    2019-06-06
  • Java中匿名類的兩種實(shí)現(xiàn)方式

    Java中匿名類的兩種實(shí)現(xiàn)方式

    本文主要介紹了Java中匿名類的兩種實(shí)現(xiàn)方式。具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-02-02
  • Java算法之堆排序代碼示例

    Java算法之堆排序代碼示例

    這篇文章主要介紹了Java算法之堆排序代碼示例,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-11-11
  • Spring Security 構(gòu)建rest服務(wù)實(shí)現(xiàn)rememberme 記住我功能

    Spring Security 構(gòu)建rest服務(wù)實(shí)現(xiàn)rememberme 記住我功能

    這篇文章主要介紹了Spring Security 構(gòu)建rest服務(wù)實(shí)現(xiàn)rememberme 記住我功能,需要的朋友可以參考下
    2018-03-03
  • IDEA解決springboot熱部署失效問題(推薦)

    IDEA解決springboot熱部署失效問題(推薦)

    熱部署,就是在應(yīng)用正在運(yùn)行的時(shí)候升級(jí)軟件,卻不需要重新啟動(dòng)應(yīng)用。這篇文章主要介紹了IDEA解決springboot熱部署失效問題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Java常用數(shù)據(jù)流全面大梳理

    Java常用數(shù)據(jù)流全面大梳理

    計(jì)算機(jī)程序中,獲取數(shù)據(jù)的方式有多種,比如:程序中直接給出、鍵盤輸入、從數(shù)據(jù)文件中讀取、從數(shù)據(jù)庫中讀取、通過網(wǎng)絡(luò)讀取等。為了更有效地進(jìn)行數(shù)據(jù)的輸入/輸出操作,Java將各種數(shù)據(jù)源的數(shù)據(jù),抽象為“數(shù)據(jù)流”,及stream
    2021-10-10
  • JAVA錯(cuò)誤:'無效目標(biāo)發(fā)行版?17'的解決方案

    JAVA錯(cuò)誤:'無效目標(biāo)發(fā)行版?17'的解決方案

    這篇文章主要給大家介紹了關(guān)于JAVA錯(cuò)誤:'無效目標(biāo)發(fā)行版?17'的解決方案,文中通過圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或使用java具有一的的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-09-09

最新評(píng)論