赞
踩
192.168.140.10 jenkins.linux.com
192.168.140.11 git服务器,存放项目源码
192.168.140.12 tomcat业务服务器
[root@gitlab ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.140.11 gitlab.linux.com
[root@gitlab ~]# yum install -y gitlab-ce-10.1.5-ce.0.el7.x86_64.rpm
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.linux.com'
[root@gitlab ~]# gitlab-ctl reconfigure
$ git init
$ git add ./*
$ git commit -m "Initial commit"
$ git remote add origin <自己的仓库地址>
$ git push -u origin master
1、git
2、gitlab
3、maven intergration
4、pushlish over ssh
[root@jenkins ~]# yum install -y git
[root@jenkins ~]# tar xf apache-maven-3.6.3-bin.tar.gz -C /usr/local/
[root@jenkins ~]# mv /usr/local/apache-maven-3.6.3/ /usr/local/maven36
[root@jenkins ~]# vim /etc/profile
export MAVEN_HOME=/usr/local/maven36
export PATH=$PATH:$MAVEN_HOME/bin
[root@jenkins ~]# source /etc/profile
[root@jenkins ~]# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/maven36
Java version: 17.0.10, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-17-oracle-x64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.el7.x86_64", arch: "amd64", family: "unix"
[root@jenkins ~]# ssh-keygen -t rsa
[root@jenkins ~]# ssh-copy-id root@192.168.140.12
设置拉取代码、编译项目的条件、时间
发布的项目文件路径、业务服务器执行的脚本
D:\test\src\main\webapp
$ git add ./*
$ git commit -m "update01"
$ git push -u origin master
项目代码push完毕后,在jenkins手动构建
https://www.jenkins.io/doc/book/pipeline/syntax/
Jenkins file, 也称为pipeline 流水线
依赖于pipeline插件
灵活
pipeline { agent any stages { stage('Build') { steps { // } } stage('Test') { steps { // } } stage('Deploy') { steps { // } } } }
配置jenkins用户与业务服务器间的ssh免密
[root@jenkins ~]# su - jenkins
Last login: Sat Jun 29 16:25:17 CST 2024 on pts/0
-bash-4.2$ ssh-keygen -t rsa
-bash-4.2$ ssh-copy-id root@192.168.140.12
pipeline { agent any stages { stage('clone') { steps { checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'http://gitlab.linux.com/root/test.git']]) } } stage('build') { steps { sh "cd /var/lib/jenkins/workspace/helloProject" sh "/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven/bin/mvn package" } } stage('deploy') { steps { sh "scp target/*.war root@192.168.140.12:/usr/local/tomcat90/webapps/hello.war" } } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。