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. Python学习笔记组织文件之将指定目录下的指定格式文件压缩到指定文件夹

    随笔记录方便自己和同路人查阅. #------------------------------------------------我是可耻的分割线--------------------------- ...

  2. 华三防火墙主备ACL

    dis cur | in policy 查看 policy-based-route 有线网络 permit node 5 policy-based-route 有线网络 permit node 10 ...

  3. WPF 后台实现按数字键滚动DataGrid 当前选中项

    最近遇到个项目,设备上没有鼠标,界面为全屏的一个DataGrid,需要实现按小键盘的0和1让DataGrid的当前选中行进行上下滚动 起到重要参考的是:   https://blog.csdn.net ...

  4. 简单的js hook

    // ==UserScript== // @name ethereum request // @namespace http://tampermonkey.net/ // @version 0.1 / ...

  5. js滚动加载数据

    话不多说,直接上代码,有些地方需要加自己的逻辑,自己加 <!DOCTYPE html><html><head lang="en"> <me ...

  6. 关于JavaScript的一些用法

    关于JavaScript的死链设置问题<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> ...

  7. 使用端口排查解决启动Tomcat端口被占问题

    有时候在eclipse中启动Tomcat或启动纯净版的Tomcat会出现端口被占的问题,下面菜鸟小编带大家进行端口排查解决问题.(下面假设是我的80端口被占了,如果你不知道你的Tomcat端口是多少就 ...

  8. <一>JDK/MAVEN/IDEA/MYSQL/GIT详细环境安装

    一.  安装JDK 1. jdk安装包下载地址:https://www.oracle.com/java/technologies/javase-jdk16-downloads.html 2. 解压缩软 ...

  9. 关于js闭包的基础理解

    闭包 拿一个可以记录函数调用次数的来进行理解,如下方 let n = 0 function numUp(){ n++ console.log(n) } const fn = numUp() fn() ...

  10. 分布式中间件MyCat 使用

    MySQL 分布式软件MyCAT介绍 目录 MySQL 分布式软件MyCAT介绍 一.MySQL 分布式软件MyCAT介绍 1.1.1 MySQL 分布式软件MyCAT介绍 1.1.2 MyCat 架 ...