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. centos6.x配置虚拟主机名及域名hosts

    我们在本地安装了centos或者虚拟主机上安装了centos,主机名称默认是localhost,这样我们可以使用localhost访问我们的主机,在终端命令里默认的是[root@localhost ~ ...

  2. 1255. 得分最高的单词集合 (Hard)

    问题描述 1255. 得分最高的单词集合 (Hard) 你将会得到一份单词表 words,一个字母表 letters (可能会有重复字母),以及每个字母对应的得分情况表 score. 请你帮忙计算玩家 ...

  3. Springboot实现文件上传下载功能

    一.文件上传 1. controller层 @RestController @RequestMapping(value = "/excel") public class Uploa ...

  4. MySQL(1): 基本操作

    MySQL 是流行的关系型数据库管理系统之一,特别是在WEB应用方面.推荐用5.6版本. My Sql客户端有很多 还有PHP MyAdmin, 是以web形式控制和操作MySQL数据库的管理工具.是 ...

  5. net/http

    客户端 GET POST form表单 json body二进制流 上传文件 PUT DELETE HEAD 重定向 Client Request Response Cookie CookieJar ...

  6. PowerDesigner 从数据库生成实体模型关键步骤

  7. Jetpack compose学习笔记之列表(布局)

    一,简介 Jetpack compose中的布局主要分为Column,Row,Box. 二,Column创建的列表 Column创建list时,不管内容是在屏幕内还是屏幕外,都会将list的内容全部创 ...

  8. 算法题:消除字符串中全部的b和连续的ac

    最近碰到了一道面试题,虽然不难但是临试没想出好的解法,记录下来以作分享. 题目:消除字符串中全部的b和连续的ac 用例: 'aabbc' -> 'a' 'aaabbbccc' -> '' ...

  9. 【LeetCode】 907 子数组的最小值之和

    Decrisption Given an array of integers arr, find the sum of min(b), where b ranges over every (conti ...

  10. 2月22日javaweb学习之Maven

    Maveb是专门用于管理和构建java项目的工具,它的主要功能有: 1.提供一套标准化的项目结构. 2.提供一套标准化的构建流程(编译.测试.打包.发布......) 3.提供了一套依赖管理机制 Ma ...