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 ...
随机推荐
- rust在windows上编译成liunx可执行程序
一.rust编译文件 cargo build 或 cargo build --release 发布构建 二.安装 x86_64-unknown-liunx-musl target rustup tar ...
- P7074 [CSP-J2020] 方格取数
目录 题目 思路 code 题目 题目链接https://www.luogu.com.cn/problem/P7074 思路 用dp[i][j][0]表示在(i,j)从左边来的最大值 用dp[i][j ...
- Day 22 22.2:scrapy部署
scrapy项目部署 scrapyd部署工具介绍 scrapyd是一个用于部署和运行scrapy爬虫的程序,它由 scrapy 官方提供的.它允许你通过JSON API来部署爬虫项目和控制爬虫运行. ...
- CF446D 题解
题意 传送门 给定一张 \(n\) 个点 \(m\) 条边的无向图,每个节点有权值 \(v_i=\) \(0/1\).角色从节点 \(1\) 开始随机游走,走到 \(n\) 停止.求其经过路径上权值和 ...
- SSH 秘钥登入
1.打开权限 vim /etc/ssh/sshd_config 去掉 PubkeyAuthentication yes 一行的# 2.重启ssh服务 systemctl restart ss ...
- js - class 操作
js - class 操作 // 添加 function addClass(dom, classNameString = '') { if (!dom.className.length) dom.cl ...
- mysql 1130报错只允许localhost登录解决方法
提示:这些方法会改变登录权限,如果是生产服务器端谨慎操作!!! mysql出现错误码1130的解决办法: 错误描述: 错误代码:1130Host ***.***.***.*** is not allo ...
- 051_Lightning 定义 直接翻译来的
那么为什么要命名为"Lightning"?那么,想一想关于实际Lightning,你在暴风雨中看到的那种.想想它的速度有多快,如果你眨眼,你可能会想念它.想想它是多么美丽; Lig ...
- 「SOL」射命丸文的笔记 (洛谷)
讲题人:"这是一个很经典的模型,大家应该都会" 我:"???" # 题面 给出 \(m\),求所有 \(m\) 个点的有标号强联通竞赛图的哈密顿回路数量的平均数 ...
- PHP Redis - zSet(有序集合)
有序集合与集合一样,string类型元素的集合,不允许重复的成员. 有序集合,每个元素都会关联一个 double 类型的分数.Redis 通过分数为集合的成员进行从小到大的排序 有序集合的成员是唯一的 ...