首页 > 其他分享 >jenkins脚本

jenkins脚本

时间:2022-12-20 17:56:13浏览次数:34  
标签:脚本 remote name xxx params jenkins root stage

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"
}
}
}
}
}

 

标签:脚本,remote,name,xxx,params,jenkins,root,stage
From: https://www.cnblogs.com/beilong/p/16994784.html

相关文章

  • JENKINS突然访问不了网页
    今天上午,JENKINS网站远程突然访问不了,只能本地使用,最后确定是防火墙的事。在JENKINS服务器上要将所有防火墙关闭:局域网和外网的,其它机器才能打开JENKINS网页。 IT工程......
  • python抓网页资源小脚本
    #!/usr/bin/envpython#coding:utf-8importurllibdeffilter_src(file_name):resource_list=[]f_obj=open(file_name)forf_lineinf_obj:if'......
  • 油猴插件的下载、安装、使用教程及几个好用的脚本推荐
    Chrome浏览器(及基于Chromium内核的各种版本浏览器)之所以受到众多用户喜爱,除了它界面简洁、速度很快之外,另一方面就是它拥有各种各样功能丰富的扩展插件,可以实现屏蔽广告、页......
  • GitHub/GitLab 为不同的项目修改提交名字 user.name 和邮箱 user.email(附:批量处理脚本
    背景大疫情的背景下,家里的电脑需要同时支撑自己和公司的项目,根据GitHub/GitLab网站的提交记录上看,其是根据邮箱来辨识用户的,所以有必要分别针对不同的项目设置不同的Gi......
  • shell脚本判断一个数是否为素数
    #!/bin/bashletisPrime=1echo"inputanumber:"readnif[${n}-le1]thenletisPrime=2fifor((i=2;i<n;i++))dolettmp=$(($n%$i))if[$tmp-......
  • Jenkins Debian Packages
    https://pkg.jenkins.io/debian/installThisistheDebianpackagerepositoryofJenkinstoautomateinstallationandupgrade.Tousethisrepository,firstadd......
  • python3.7登录脚本
    下面是登录脚本,最后获取token值test${headers}   CreateDictionary  Content-Type=application/json    User-Agent=Mozilla/5.0(WindowsNT10.0;......
  • 自动备份mysql数据库 - shell脚本
     以下是自动备份mysql数据库的全过程:使用mysqldump程序连接到MySQL服务器。将指定的数据库存储到SQL文件。压缩SQL文件以节省空间。要使用此脚本,您需要修改脚本顶......
  • Jenkins使用笔记
    jenkins搭建部署分为三个步骤;第一步,jenkins安装第二步,插件安装和配置第三步,PushSSH第四步,部署项目准备环境:​​JDK:1.8:安装​​maven3.5‘安装Jenkins:2.83Centos:7.......
  • Azure脚本分享,批量导出用户MFA状态
    一年时间又快过去了,又攒了一些内容可以拿出来分享,希望能帮到有需要的人,先从一些比较简单的开始吧,最近有个需求是想看到用户是不是都设置了MFA,设置了MFA代表相对来说比较安全......