持续集成之将代码自动部署至测试环境(2)

#!/bin/bash
cd /home/www/web-demo_deploy/ #进入到本地代码库
git pull #从git服务器更新代码
scp -r ./* www@192.168.3.12:/webroot/web_www #将代码部署至web服务器
scp -r ./* www@192.168.3.13:/webroot/web_www
www@192.168.3.12 $ chmod +x dep.sh

1.3.3.2:在jenkins调用脚本:
#在项目的构建步骤调用,项目-配置-构建-增加构建步骤-Execute shell

持续集成之将代码自动部署至测试环境

持续集成之将代码自动部署至测试环境

访问web页面测试:

持续集成之将代码自动部署至测试环境

在git仓库创建代码并更新至git服务器:

[www@master web-demo_deploy]$ vim index.html # 添加
[www@master web-demo_deploy]$ git add index.html
[www@master web-demo_deploy]$ git commit -m 'edit index.html add '
[master 51f8f11] edit index.html add
1 file changed, 1 insertion(+), 1 deletion(-)
[www@master web-demo_deploy]$ git push origin master
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 313 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To git@192.168.3.198:web/web-demo_deploy.git
ac41e81..51f8f11 master -> master

再次在jenkins执行项目构建

可以看到刚刚更新的代码获取成功

持续集成之将代码自动部署至测试环境

1.4:让代码测试项目管理代码发布项目,当代码测试的项目执行成功之后自动调用代码发布的项目完成代码部署:
1.4.1:安装插件,jenkins的插件默认安装路径

# ll /var/lib/jenkins/plugins/

tomcat版本的安装路径:

/usr/local/tomcat/webapps/jenkins/WEB-INF/detached-plugins/

如果插件在线安装不成功可以下载插件到此目录然后把属主属组改成jenkins再重启jenkins服务即可完成安装:
#系统管理-管理插件-可选插件,搜索Parameterized:

持续集成之将代码自动部署至测试环境

1.4.2:配置项目demo的构建后操作,demo构建完成后自动构建demp-deploy项目:
#jenkins-->web-demo-->配置-->构建后操作:

持续集成之将代码自动部署至测试环境

1.4.3:配置如下:

持续集成之将代码自动部署至测试环境

1.5:测试,执行代码测试项目成功之后是否会自动执行代码部署项目:

控制台输出

Started by user admin
Building in workspace /home/jenkins/.jenkins/workspace/web-demo
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url git@192.168.3.198:web/web-demo.git # timeout=10
Fetching upstream changes from git@192.168.3.198:web/web-demo.git
> git --version # timeout=10
using GIT_SSH to set credentials gitlab_web-demo
> git fetch --tags --progress git@192.168.3.198:web/web-demo.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision b8f3be4385efdf64606158c23f9f1992bb2da1d3 (refs/remotes/origin/master)
Commit message: "add "
> git config core.sparsecheckout # timeout=10
> git checkout -f b8f3be4385efdf64606158c23f9f1992bb2da1d3
> git rev-list b8f3be4385efdf64606158c23f9f1992bb2da1d3 # timeout=10
[web-demo] $ /usr/local/sonar-scanner/bin/sonar-scanner -e -Dsonar.host.url=http://192.168.3.199:9000/ -Dsonar.language=php -Dsonar.projectName=web-demo -Dsonar.projectVersion=1.0 -Dsonar.sourceEncoding=UTF-8 -Dsonar.projectKey=web-demo -Dsonar.sources=./ -Dsonar.projectBaseDir=/home/jenkins/.jenkins/workspace/web-demo
INFO: Scanner configuration file: /usr/local/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 2.6.1
INFO: Java 1.8.0_111 Oracle Corporation (64-bit)
INFO: Linux 3.10.0-514.el7.x86_64 amd64
INFO: Error stacktraces are turned on.
INFO: User cache: /home/jenkins/.sonar/cache
INFO: Load global repositories
INFO: Load global repositories (done) | time=172ms
WARN: Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
WARN: Property 'sonar.jdbc.username' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
WARN: Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
INFO: User cache: /home/jenkins/.sonar/cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=3ms
INFO: SonarQube server 5.6.6
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=97ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=34ms
INFO: Load active rules
INFO: Load active rules (done) | time=380ms
WARN: SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project.
INFO: Publish mode
INFO: ------------- Scan web-demo
INFO: Language is forced to php
INFO: Load server rules
INFO: Load server rules (done) | time=71ms
INFO: Base dir: /home/jenkins/.jenkins/workspace/web-demo
INFO: Working dir: /home/jenkins/.jenkins/workspace/web-demo/.sonar
INFO: Source paths: .
INFO: Source encoding: UTF-8, default locale: en_US
INFO: Index files
INFO: 0 files indexed
INFO: Quality profile for php: Sonar way
INFO: Sensor Lines Sensor
INFO: Sensor Lines Sensor (done) | time=0ms
INFO: Sensor SCM Sensor
INFO: No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
INFO: Sensor SCM Sensor (done) | time=0ms
INFO: Sensor Analyzer for "php.ini" files
INFO: Sensor Analyzer for "php.ini" files (done) | time=3ms
INFO: Sensor SonarJavaXmlFileSensor
INFO: Sensor SonarJavaXmlFileSensor (done) | time=0ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=0ms
INFO: Sensor Code Colorizer Sensor
INFO: Sensor Code Colorizer Sensor (done) | time=0ms
INFO: Sensor CPD Block Indexer
INFO: DefaultCpdBlockIndexer is used for php
INFO: Sensor CPD Block Indexer (done) | time=0ms
INFO: Calculating CPD for 0 files
INFO: CPD calculation finished
INFO: Analysis report generated in 47ms, dir size=8 KB
INFO: Analysis reports compressed in 7ms, zip size=3 KB
INFO: Analysis report uploaded in 47ms
INFO: ANALYSIS SUCCESSFUL, you can browse :9000/dashboard/index/web-demo
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at :9000/api/ce/task?id=AV0YJcbrykzBCcoFv4Mt
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 43.045s
INFO: Final Memory: 42M/137M
INFO: ------------------------------------------------------------------------
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Triggering a new build of web-demo_deploy
Finished: SUCCESS

1.6:pipeline插件:
1.6.1:#安装插件,系统管理-管理插件-可安装插件:

持续集成之将代码自动部署至测试环境

1.6.2:创建视图:

持续集成之将代码自动部署至测试环境

1.6.3:自定义名称:

持续集成之将代码自动部署至测试环境

持续集成之将代码自动部署至测试环境

持续集成之将代码自动部署至测试环境

持续集成之将代码自动部署至测试环境

1.6.4:配置pipeline信息,点击OK之后,弹出如下视图

点击保存之后显示的最终界面:

持续集成之将代码自动部署至测试环境

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e11da3b1a9efd01dc5b1326a8470d993.html