1. 程式人生 > 其它 >|NO.Z.00052|——————————|^^ 操作 ^^|——|CI/CD&Jenkins_Harbor操作.V09|--------------------------------------------|Jenkins_Job構建.V03|

|NO.Z.00052|——————————|^^ 操作 ^^|——|CI/CD&Jenkins_Harbor操作.V09|--------------------------------------------|Jenkins_Job構建.V03|



[CloudNative:CI/CD&Jenkins_Harbor操作.V09]                                                      [Applications.CloudNative] [|Jenkins向docker中部署專案|Post setps.配置shell指令碼|Jenkins遠端站點配置|Jenkins.Job執行構建|]








一、CI/CD.Jenkins.Job構建:Jenkins.Job構建
二、控制檯輸出過程
### --- 控制檯輸出

Started by user yanqi
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/maven-docker
The recommended git tool is: NONE
No credentials specified
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url [email protected]:/home/git/easy-springmvc-maven.git # timeout=10
Fetching upstream changes from [email protected]:/home/git/easy-springmvc-maven.git
 > git --version # timeout=10
 > git --version # 'git version 1.8.3.1'
 > git fetch --tags --progress [email protected]:/home/git/easy-springmvc-maven.git +refs/heads#/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision f7c9320a8a2ddfd0dba47fcec7dbefdaca4aee23 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f f7c9320a8a2ddfd0dba47fcec7dbefdaca4aee23 # timeout=10
Commit message: "jenkins"       "修改standard/1.1.2的依賴"
 > git rev-list --no-walk f7c9320a8a2ddfd0dba47fcec7dbefdaca4aee23 # timeout=10
Parsing POMs
Established TCP socket on 45353
[maven-docker] $ java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-agent-1.13.jar:/usr/share/maven/boot/plexus-classworlds.jar org.jvnet.hudson.maven3.agent.Maven3Main /usr/share/maven /var/cache/jenkins/war/WEB-INF/lib/remoting-4.6.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-1.13.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.13.jar 45353
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f /var/lib/jenkins/workspace/maven-docker/pom.xml clean package -Dmaven.test.skip=true
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for springmvc-maven:easy-springmvc-maven:war:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-war-plugin is missing. @ line 22, column 15
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] •[1m----------------< •[0;36mspringmvc-maven:easy-springmvc-maven•[0;1m >----------------•[m
[INFO] •[1mBuilding springmvc-maven 0.0.1-SNAPSHOT•[m
[INFO] •[1m--------------------------------[ war ]---------------------------------•[m
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ easy-springmvc-maven ---
[INFO] Deleting /var/lib/jenkins/workspace/maven-docker/target
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ easy-springmvc-maven ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/maven-docker/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ easy-springmvc-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /var/lib/jenkins/workspace/maven-docker/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ easy-springmvc-maven ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/maven-docker/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ easy-springmvc-maven ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ easy-springmvc-maven ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ easy-springmvc-maven ---
[INFO] Packaging webapp
[INFO] Assembling webapp [easy-springmvc-maven] in [/var/lib/jenkins/workspace/maven-docker/target/easy-springmvc-maven]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/lib/jenkins/workspace/maven-docker/src/main/webapp]
[INFO] Webapp assembled in [95 msecs]
[INFO] Building war: /var/lib/jenkins/workspace/maven-docker/target/easy-springmvc-maven.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] •[1m------------------------------------------------------------------------•[m
[INFO] •[1;32mBUILD SUCCESS•[m
[INFO] •[1m------------------------------------------------------------------------•[m
[INFO] Total time: 5.373 s
[INFO] Finished at: 2021-04-01T22:04:26+08:00
[INFO] •[1m------------------------------------------------------------------------•[m
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /var/lib/jenkins/workspace/maven-docker/pom.xml to springmvc-maven/easy-springmvc-maven/0.0.1-SNAPSHOT/easy-springmvc-maven-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /var/lib/jenkins/workspace/maven-docker/target/easy-springmvc-maven.war to springmvc-maven/easy-springmvc-maven/0.0.1-SNAPSHOT/easy-springmvc-maven-0.0.1-SNAPSHOT.war
channel stopped
[maven-docker] $ /bin/sh -xe /tmp/jenkins7471956269803087309.sh
+ JENKINS_WAR_HOME=/var/lib/jenkins/workspace/maven-docker/target
+ DOCKERFILE_HOME=/var/lib/jenkins/docker-file/maven-docker-test_war
+ HARBOR_IP=10.10.10.11
+ REPOSITORIES=jenkins/maven-docker
+ HARBOR_USER=yanqi
+ HARBOR_USER_PASSWD=Harbor12345
+ [email protected]
+ cp -f /var/lib/jenkins/workspace/maven-docker/target/easy-springmvc-maven.war /var/lib/jenkins/docker-file/maven-docker-test_war/maven-docker.war
+ sudo docker login -u yanqi -p Harbor12345 10.10.10.11:80
Login Succeeded
++ sudo docker images
++ awk '{print $3}'
++ grep jenkins/maven-docker
+ IMAGE_ID=3ca27a216b15
+ '[' -n 3ca27a216b15 ']'
+ sudo docker rmi 3ca27a216b15
Untagged: 10.10.10.11:80/jenkins/maven-docker:20210401-215916
Untagged: 10.10.10.11:80/jenkins/maven-docker@sha256:e14d7ce0dc4e8a778c02b9a23603c2b568e4149091764918824314918d10802e
Deleted: sha256:3ca27a216b15bcf6d8363e4053603ec9499e22e59b84f5252f33af6ab7493cd8
Deleted: sha256:ea0602601a9fdc8df2bcebf3f1b56b4b9e4c02df359fd105c5621a4a77aa8c8f
Deleted: sha256:a9417c1adbd62bb0be4163be4d99e140b5c642d76d32ee8829a4b0b1c6c24eb5
Deleted: sha256:418cf4676c0672513cdaaa1c6eccc6fe6f236745e311968ce5385f8a462cc2ee
Deleted: sha256:04deeb07c4d5a3c0867eb0a7bf214d256cf8a30010b12d08b07886749c84e2c9
Deleted: sha256:1e893409946bfc630c0775bdfc69f6702eadba03017bf59562b0b22a89738f81
Deleted: sha256:c8461cc64f1938ebb3f51105115fce4bde851397ed68ed42adfafc5014f206f4
+ cd /var/lib/jenkins/docker-file/maven-docker-test_war
++ date +%Y%m%d-%H%M%S
+ TAG=20210401-220427
+ sudo docker build -t 10.10.10.11:80/jenkins/maven-docker:20210401-220427 .
+ sudo docker push 10.10.10.11:80/jenkins/maven-docker:20210401-220427
[SSH] script:

# 拉取映象,釋出
HARBOR_IP='10.10.10.11'
REPOSITORIES='jenkins/maven-docker'
HARBOR_USER='yanqi'
HARBOR_USER_PASSWD='Harbor12345'
 
# 登入harbor
docker login -u ${HARBOR_USER} -p ${HARBOR_USER_PASSWD} ${HARBOR_IP}:80
 
# Stop container, and delete the container.
CONTAINER_ID=`docker ps | grep "maven-docker" | awk '{print $1}'`
if [ -n "$CONTAINER_ID" ]; then
    docker stop $CONTAINER_ID
    docker rm $CONTAINER_ID
else #如果容器啟動時失敗了,就需要docker ps -a才能找到那個容器
    CONTAINER_ID=`docker ps -a | grep "maven-docker" | awk '{print $1}'`
    if [ -n "$CONTAINER_ID" ]; then  # 如果是第一次在這臺機器上拉取執行容器,那麼docker ps -a也是找不到這個容器的
        docker rm $CONTAINER_ID
    fi
fi
 
# Delet eeasy-springmvc-maven image early version.
IMAGE_ID=`sudo docker images | grep ${REPOSITORIES} | awk '{print $3}'`
if [ -n "${IMAGE_ID}" ];then
    docker rmi ${IMAGE_ID}
fi
 
# Pull image.
# TAG=`curl -s http://${HARBOR_IP}/api/repositories/${REPOSITORIES}/tags | jq '.[-1]' | sed 's/\"//g'`
# TAG=`curl -s http://10.10.10.11/api/repositories/jenkins/maven-docker/tags | jq '.[-1]| {name:.name}' | awk -F '"' '/name/{print $4}'`
TAG=`curl -s http://10.10.10.11/api/v2.0/projects/jenkins/repositories/maven-docker/artifacts |awk -F'name":"' '{print $2}'|cut -d '"' -f1`
docker pull ${HARBOR_IP}:80/${REPOSITORIES}:${TAG} &>/dev/null
 
# Run.
docker run -d --name maven-docker -p 8080:8080 ${HARBOR_IP}:80/${REPOSITORIES}:${TAG}

[SSH] executing...
Login Succeeded
d742fccf99af36073ce44dbdf6d3976343ef342d60c5f44ae9344777ac437344

[SSH] completed
[SSH] exit-status: 0

Finished: SUCCESS
三、驗證是否部署成功
### --- 驗證是否部署成功:在docker應用伺服器上檢視
~~~     # 檢視拉取的映象

[root@docker ~]# docker images
REPOSITORY                            TAG                 IMAGE ID            CREATED              SIZE
10.10.10.11:80/jenkins/maven-docker   20210401-223405     952b37d8935a        About a minute ago   153MB
~~~     # 檢視部署的應用

[root@docker ~]# docker ps
CONTAINER ID        IMAGE                                                 COMMAND             CREATED              STATUS              PORTS                    NAMES
56ffbf5b7ab2        10.10.10.11:80/jenkins/maven-docker:20210401-223405   "catalina.sh run"   About a minute ago   Up About a minute   0.0.0.0:8080->8080/tcp   maven-docker








===============================END===============================


Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart                                                                                                                                                    ——W.S.Landor



來自為知筆記(Wiz)