jenkins脚本
1.统计代码
pipeline {
agent any
parameters {
choice(
description: '你需要选择当前哪个分支进行统计 ?',
name: 'branchNow',
choices: ['release-v2.0.0', 'release-v1.1.1','master']
)
choice(
description: '你需要选择过去哪个分支进行比较 ?',
name: 'branchOld',
choices: ['release-v1.1.1,'master','release-v1.1.0']
)
}
stages {
stage('Checkout1') {
steps {
echo "checkout stage: 当前分支为 : ${params.branchNow} ..."
checkout([$class: 'GitSCM', branches: [[name: "${params.branchNow}"]], extensions: [[$class: 'CleanBeforeCheckout']], userRemoteConfigs: [[credentialsId: '4bed03cf-6c80-4533-b89a-b9fa4168af17', url: 'https://xxx/xxx.git']]])
sh """cp -r ../backend-countTask ../backend-countTask-${params.branchNow}"""
}
}
stage('Checkout2') {
steps {
echo "checkout stage: 当前分支为 : ${params.branchOld} ..."
checkout([$class: 'GitSCM', branches: [[name: "${params.branchOld}"]], extensions: [[$class: 'CleanBeforeCheckout']], userRemoteConfigs: [[credentialsId: '4bed03cf-6c80-4533-b89a-b9fa4168af17', url: 'https://xxx/xxx.git']]])
sh """git branch"""
sh """cloc --fullpath --ignore-whitespace --diff ../backend-countTask ../backend-countTask-${params.branchNow}"""
sh """rm -rf ../backend-countTask-${params.branchNow}"""
}
}
}
}
2.编译部署
1.前端
pipeline {
agent any
parameters {
choice(
description: '你需要选择哪个主机进行构建 ?',
name: 'host_ip',
choices: ['x.x.x.1', 'x.x.x.2']
)
choice(
description: '你需要选择哪个分支进行构建 ?',
name: 'branch',
choices: ['dev','master','release']
)
}
environment {
HOST_IP = "${params.host_ip}"
}
stages {
stage('Checkout') {
steps {
echo "checkout stage: 选中的构建分支为 : ${params.branch} ..."
checkout([$class: 'GitSCM', branches: [[name: "${params.branch}"]], extensions: [[$class: 'CleanBeforeCheckout']], userRemoteConfigs: [[credentialsId: '4bed03cf-6c80-4533-b89a-b9fa4168af17', url: 'https://xxx/xxx.git']]])
}
}
stage('Build') {
steps {
echo "build stage: npm install;npm build"
sh "npm install --registry=https://registry.npm.taobao.org"
sh "npm run build"
}
}
stage('SSH deploy') {
steps {
echo "SSH stage: 选中的部署主机为 : ${params.host_ip} ..."
script {
def remote = [:]
remote.name = 'ui'
remote.host = HOST_IP
remote.user = 'root'
remote.password = 'xxx'
remote.allowAnyHosts = true
sshCommand remote: remote, command: "pwd"
sshCommand remote: remote, command: "ls"
sshRemove remote: remote, path: '/root/deploy/ui/dist'
sshPut remote: remote, from: '/root/jenkins/workspace/ui/dist.tar', into: '/root/deploy/ui/'
sshCommand remote: remote, command: "cd /root/deploy/ui/ && tar xzvf dist.tar && bash redeploy.sh"
}
}
}
}
}
2.后端
pipeline {
agent any
parameters {
choice(
description: '你需要选择哪个主机进行构建 ?',
name: 'host_ip',
choices: ['x.x.x.1', 'x.x.x.2']
)
choice(
description: '你需要选择哪个分支进行构建 ?',
name: 'branch',
choices: ['dev','release','master']
)
}
environment {
HOST_IP = "${params.host_ip}"
}
stages {
stage('Checkout') {
steps {
echo "checkout stage: 选中的构建分支为 : ${params.branch} ..."
checkout([$class: 'GitSCM', branches: [[name: "${params.branch}"]], extensions: [[$class: 'CleanBeforeCheckout']], userRemoteConfigs: [[credentialsId: '4bed03cf-6c80-4533-b89a-b9fa4168af17', url: 'https://xxx/xxx.git']]])
}
}
stage('Build') {
steps {
echo "build stage: mvn clean package"
sh "mvn clean package"
}
}
stage('SSH deploy') {
steps {
echo "SSH stage: 选中的部署主机为 : ${params.host_ip} ..."
script {
def remote = [:]
remote.name = 'back'
remote.host = HOST_IP
remote.user = 'root'
remote.password = 'xxx'
remote.allowAnyHosts = true
sshCommand remote: remote, command: "pwd"
sshCommand remote: remote, command: "ls"
// sshRemove remote: remote, path: '/usr/share/nginx/html/demo/dist'
sshPut remote: remote, from: '/root/jenkins/workspace/backend/back/target/a.jar', into: '/root/deploy/back/'
sshCommand remote: remote, command: "cd /root/deploy/back/ && bash redeploy.sh"
}
}
}
}
}
jenkins脚本的更多相关文章
- Jenkins 脚本命令行应用总结
Jenkins脚本命令行应用总结 测试环境 Jenkins 2.304 脚本命令行入口 Jenkins主页→系统管理→脚本命令行 遍历项目 例子:获取所有自由风格项目及相关项目信息 def proje ...
- 约定Jenkins构建脚本
对于Jenkins的使用,我感觉只用到其中一小部分功能,但也就是这一小部分功能,也推动了整个CI/CD的过程,Jenkins的使用方式有很多中,可能我用到的只是其中一种,但是已经满足我的需求,便不再贪 ...
- Jenkins + GitLab + SpringBoot 实现持续集成脚本
Linux脚本 #!/bin/bash jar_name=hq-api.jar cd /usr/local/app/hq-api echo "Stopping SpringBoot Appl ...
- python实用脚本-通过jenkins界面化导出数据
1.jenkins 配置 2.jenkins 脚本 ansible-playbook /opt/test.yaml --extra-vars "loanno=${loanno}" ...
- 基于Docker构建带有Rsync的Jenkins
1.编辑Dockerfile文件 FROM jenkins USER root ADD sources.list /etc/apt/sources.list RUN apt-get update &a ...
- jenkins自动化工具使用教程
自动化构建.测试.部署.代码检测越来越重要.主要有一下几点原因 1. 企业做大,项目变多,多端支持(web,h5,小程序等) 2. 微服务提倡高内聚低耦合,项目因拆分变多 3. DevOps自动 ...
- rancher2.1.7 +jenkins +harbor 自动容器CI系统(通过rancher命令行)
jenkins脚本执行示例: //环境定义与 cd $WORKSPACEmodule=news-usercd $module/case $deploy in deploy) //发布模块 //编译/o ...
- Jenkins日常运维笔记-重启数据覆盖问题、迁移、基于java代码发版(maven构建)
之前在公司机房部署了一套jenkins环境,现需要迁移至IDC机房服务器上,迁移过程中记录了一些细节:1)jenkins默认的主目录放在当前用户家目录路径下的.jenkins目录中.如jenkins使 ...
- Docker:使用Jenkins构建Docker镜像
Docker 彭东稳 1年前 (2016-12-27) 10709次浏览 已收录 0个评论 一.介绍Jenkins Jenkins是一个开源项目,提供了一种易于使用的持续集成系统,使开发者从 ...
- nslookup dig iptables,sudoer,jenkins
[NSLOOKUPm]http://roclinux.cn/?p=2441 nslookup media.ucampus.unipus.cn [DIG]http://roclinux.cn/?p=24 ...
随机推荐
- C#textbox更改字体颜色只读后不起作用的解决办法
textbox的属性ReadOnly设置为true只读后,只更改字体颜色并不起作用. 解决办法是,连同背景色一起设置即可. textBox1.BackColor =textBox1.BackColor ...
- ArrayList集合的方法
ArrayList元素的增加.插入.删除.清空.排序.反转 using System; using System.Collections; using System.Collections.Gener ...
- Mac预览怎么用 Mac预览功能实用技巧大全
Mac预览怎么用?有很多的用户以为Mac自带的预览功能只具有简单的图片浏览功能,其实不然,其实"预览"是一款强大的看图.修图.改图软件,也同时是一款多功能的 PDF 阅读与编辑工具 ...
- Qt中资源文件qrc中的路径访问
首先先看一下我们的qrc文件目录结构: 在文件系统中的目录结构是这样的: 请务必注意这边的前缀(按照网友推荐,大部分项目前缀都是只写一个"/"): 接下来进入正题,我们来分 ...
- docker从C盘迁移到D盘
docker镜像在C盘占据大量的空间,将.docker从C:\Users\Administrator迁移到E:\.docker. 一.关闭virtual Box 使virtual Box处于关闭.停止 ...
- 05 RDD练习:词频统计
一.词频统计: 1.读文本文件生成RDD lines 2.将一行一行的文本分割成单词 words flatmap() 3.全部转换为小写 lower() 4.去掉长度小于3的单词 filter() 5 ...
- c++学习2 基础关键词
三 volatile强制访问内存 在一个变量的频繁使用中,系统为了提高效率,会自动将内存里面的数据放入CPU里的寄存器里.但在某些特殊场景下,放入寄存器这个操作反倒会导致CPU无法及时获取最新的一手数 ...
- Tesstwo9.1.0配置步骤
一,配置步骤 环境:Tesstwo9.1.0+Android10(华为)+Android11(模拟器) 1.查看tess-two的最新版本(GitHub - rmtheis/tess-two: For ...
- iOS学习十二之选择器控件UIPickerView
UIPickerView是一个简易的列表控件,用于提供有限个数的选项供用户选择. 它是通过代理和数据源的方法对其进行设置和数据源填充的,这种控件的设计模式也是代理模式的应用之一. 添加下面的代码即可实 ...
- qt中的一些对话框(个人备忘录)
一.标准对话框 1.对于颜色对话框 void MyWidget::on_pushButton_clicked() { QColorDialog dialog(Qt::red,this); dialog ...