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脚本的更多相关文章

  1. Jenkins 脚本命令行应用总结

    Jenkins脚本命令行应用总结 测试环境 Jenkins 2.304 脚本命令行入口 Jenkins主页→系统管理→脚本命令行 遍历项目 例子:获取所有自由风格项目及相关项目信息 def proje ...

  2. 约定Jenkins构建脚本

    对于Jenkins的使用,我感觉只用到其中一小部分功能,但也就是这一小部分功能,也推动了整个CI/CD的过程,Jenkins的使用方式有很多中,可能我用到的只是其中一种,但是已经满足我的需求,便不再贪 ...

  3. Jenkins + GitLab + SpringBoot 实现持续集成脚本

    Linux脚本 #!/bin/bash jar_name=hq-api.jar cd /usr/local/app/hq-api echo "Stopping SpringBoot Appl ...

  4. python实用脚本-通过jenkins界面化导出数据

    1.jenkins 配置 2.jenkins 脚本 ansible-playbook /opt/test.yaml --extra-vars "loanno=${loanno}" ...

  5. 基于Docker构建带有Rsync的Jenkins

    1.编辑Dockerfile文件 FROM jenkins USER root ADD sources.list /etc/apt/sources.list RUN apt-get update &a ...

  6. jenkins自动化工具使用教程

    自动化构建.测试.部署.代码检测越来越重要.主要有一下几点原因 1.  企业做大,项目变多,多端支持(web,h5,小程序等) 2.  微服务提倡高内聚低耦合,项目因拆分变多 3.  DevOps自动 ...

  7. rancher2.1.7 +jenkins +harbor 自动容器CI系统(通过rancher命令行)

    jenkins脚本执行示例: //环境定义与 cd $WORKSPACEmodule=news-usercd $module/case $deploy in deploy) //发布模块 //编译/o ...

  8. Jenkins日常运维笔记-重启数据覆盖问题、迁移、基于java代码发版(maven构建)

    之前在公司机房部署了一套jenkins环境,现需要迁移至IDC机房服务器上,迁移过程中记录了一些细节:1)jenkins默认的主目录放在当前用户家目录路径下的.jenkins目录中.如jenkins使 ...

  9. Docker:使用Jenkins构建Docker镜像

    Docker  彭东稳  1年前 (2016-12-27)  10709次浏览  已收录  0个评论 一.介绍Jenkins Jenkins是一个开源项目,提供了一种易于使用的持续集成系统,使开发者从 ...

  10. nslookup dig iptables,sudoer,jenkins

    [NSLOOKUPm]http://roclinux.cn/?p=2441 nslookup media.ucampus.unipus.cn [DIG]http://roclinux.cn/?p=24 ...

随机推荐

  1. SSH反向隧道实现内网穿透

    1.客户端配置 /home/tsingyundev/zyy bind209.sh内容 ssh -fCNL *:1234:localhost:10022 localhost ssh209.sh内容 ss ...

  2. Django 之 Form

    forms组件 1. 校验字段功能 针对一个实例:注册用户讲解. 模型:models.py class UserInfo(models.Model): name=models.CharField(ma ...

  3. 杭电oj 求奇数的乘积

    #include <stdio.h> #include <stdlib.h> int main() { int i,n,a; int sum = 1; while(scanf( ...

  4. windows U盘启动装机工具(Ventoy)

    Windows优盘启动装机工具 一.WePE 纯净 WePE 启动盘/ U盘重装系统工具 1.U盘重装系统工具下载地址:https://www.wepe.com.cn/download.html?td ...

  5. Django中models下常用Field以及字段参数

    常见的FieldType数据库字段类型     1.AutoField:自增Field域,自动增加的一个数据库字段类型,例如id字段就可以使用该数据类型,参数中必须填入primary_key=True ...

  6. mybatis plus 分页总查出来全部数据

    需要配置过滤器 package com.tyyy.example.coreurl.config; import com.baomidou.mybatisplus.annotation.DbType; ...

  7. Taro 弹窗阻止小程序滑动穿透(亲测有效) tabbar数据缓存不更新 入口场景值不同

    v3.0 推出后反馈最多的问题之一,就是在 touchmove 事件回调中调用 e.stopPropagation() 并不能阻止滑动穿透. 这是因为 Taro 3 的事件冒泡机制是单独在小程序逻辑层 ...

  8. 实验:笔记本电脑做桥接有线网络,笔记本通过wifi连手机热点,,硬件通过笔记本的有线网口上网

    1.问题 我们需要做实验,将我们设计的W5500实验板上internet,  搭建环境比较麻烦. 1)学校上网需要先HTTP认证: 2)家里经常路由器固定位置,没有足够长的网线: 3)有时候需要临时搭 ...

  9. 基于工业5G网关的建筑机器人应用

    建筑行业是世界上数字化程度最低.自动化程度最低的行业之一.近百年来,虽然技术革新不断,建筑本身的形态和功能也大不相同,但建筑施工的业态形式却始终没有出现显著的变化. 随着人口红利的消失,中国的建筑业面 ...

  10. 侠客行+越女剑 <随笔>

    侠客行:自己提炼剧情是一个很费时费劲的事情,好在剽窃百度百科不算抄袭,而且也足够还原,红字为补充 一向平静祥和的小市镇侯监集上,忽然来了二百多名杀人不眨眼的强盗.镇上乡亲们都熟悉的卖饼老者王老汉,却被 ...