当前位置: 首页 > news >正文

jenkins 在pinline克隆代码的两种方式

在pinline克隆代码的两种方式

  • 1.pipline语法直接实现方式
    • 1.1例子1
    • 1.2例子2
  • 2.jenkins pinline 流水线中调用 shell脚本方式

jenkins搭建流水线从拉取代码开始其实是最正规的方式,但是如何拉取有多种方式
可以用jenkins的插件以钩子的形式,也可以在pipline脚本中实现,今天介绍两种 pipline方式实现拉取代码的方式。

1.pipline语法直接实现方式

1.1例子1

pipeline {agent anystages {stage('Project1'){steps{cleanWs()dir('project1') {// Doing your project 1 stuffgit(url: 'https://github.com/xxx/proj1.git', branch: 'main')}}}stage('Project 2'){steps{dir('project2') {// Doing your project 2 stuffgit(url: 'https://github.com/xxx/proj2.git', branch: 'dev')}}}stage('Something Else'){steps{sh 'ls -al'         }}}
}

1.2例子2

pipeline {agent anystages {stage('Project1'){steps{cleanWs()echo "Let's move proj 1 stuff to a sub dir"sh '''mkdir project1shopt -s extglob dotglobmv !(project1) project1'''}}stage('Project 2'){steps{dir('project2') {// Doing your project 2 stuffgit(url: 'https://github.com/xxx/proj2.git', branch: 'main')}}}stage('Something Else'){steps{sh 'ls -al'               }}}
}

2.jenkins pinline 流水线中调用 shell脚本方式

这种方式需要服务器预先安装好了git

pipline中调用shell脚本

def CustomizeRepos = ''
def Baseline = 'false'
def VersionInfo=''
def testMessage=''
def Pr_CustomizeRepos = ""pipeline {agent {label 'le-node'}parameters {string(name: 'BRANCHNAME', defaultValue: 'develop', description: '代码分支名称')}environment {JENKINS_NODE_COOKIE = 'dontKillMe'project_path = '/automation/code/'pipeline_git_tool = '/automation/scripts/build_gitclone.sh'url = 'https://gitee.com/burebaobao/tscancode-master.git'}stage("下载平台代码") {steps {script {echo "开始克隆代码"sh "cd ${project_path}"// 调用脚本sh "${env.pipeline_git_tool} '${project_path}' '${BRANCHNAME}' '${url}'"}}}}

所调用的shell脚本

#!/bin/bash#########################################
#代码clone脚本
#参数:
# path 代码存储路径
# branch 代码分支名
# url 地址
##########################################参数判断 
if [ $# != 3 ]; thenecho "参数输入错误,输入必须包括path、Branch、url参数!"exit -1
fipath=$1
branch=$2
url=$3echo "开始"
echo "切换路径到 $path"
cd ${path}echo "克隆的代码分支为 ${branch}"mcd="git clone -b ${branch} --single-branch https://gitee.com/burebaobao/tscancode-master.git"
git clone -b ${branch} --single-branch ${url}
http://www.lryc.cn/news/114832.html

相关文章:

  • Python入门【​编辑、组合、设计模式_工厂模式实现 、设计模式_单例模式实现、工厂和单例模式结合、异常是什么?异常的解决思路 】(十七)
  • 65 # 实现 http-server 里的 gzip 压缩
  • 点成分享丨qPCR仪的原理与使用——以Novacyt产品为例
  • Postman如何做接口测试
  • 每天一道leetcode:剑指 Offer 32 - II. 从上到下打印二叉树 II(适合初学者)
  • vue动态生成行
  • IPC之一:使用匿名管道进行父子进程间通信的例子
  • 前端将页面转化为图片---进行下载导出、打印等功能
  • docker安装code-service在线开发vscode工具及node版本过低问题
  • C++ 多态深入解析
  • C#使用EmguCV播放视频
  • LeetCode150道面试经典题-买卖股票的最佳时机(简单)
  • 【积水成渊】CSS磨砂玻璃效果和渐变主题色文字
  • JVM、JRE、JDK三者之间的关系
  • input 标签的 type 属性有哪些值?分别表示什么意思?
  • (十五)大数据实战——hive的安装部署
  • MySQL安装和卸载
  • ELK、ELFK日志分析系统
  • JVM基础篇-StringTable
  • 探秘手机隐藏的望远镜功能:开启后,观察任何你想看的地方
  • 正运动亮相2023半导体设备材料与核心部件展示会,助力半导体产业高速高精应用
  • 如何在MongoDB中添加新用户
  • 幻读怎么复现
  • 无脑入门pytorch系列(二)—— torch.mean
  • ansible-kubeadm在线安装高可用K8S集群v1.19-v1.20版本
  • Cesium entity 渐隐渐显、闪烁
  • LISA:通过大语言模型进行推理分割
  • opencv基础40-礼帽运算(原始图像减去其开运算)cv2.MORPH_TOPHAT
  • php中的array_filter()函数
  • ArcGIS Pro基础:【按顺序编号】工具实现属性字段的编号自动赋值