Jenkinsfile

https://jenkins.io/doc/book/pipeline/jenkinsfile/

Jenkins Pipeline is a suite of plugins that supports implementing and integrating continuous delivery pipelines into Jenkins. Pipeline provides an extensible set of tools for modeling simple-to-complex delivery pipelines "as code" via the Pipeline DSL.

例子&教程:

https://github.com/ciandcd

http://www.cnblogs.com/itech/p/5875428.html

以脚本形式定义 持续集成步骤,与界面配置相比, 其支持多业务融合, 具有更加的灵活性、扩展性,便于定位集成过程中发现的问题。

但是脚本方式融合了若干业务后, 就徽导致脚本代码繁杂, 不易于维护。 且不能达到业务配置和脚本公共逻辑分离的目的。

为解决这个问题, 存在两种解决方案, 下面分别介绍。

load 加载方式

https://stackoverflow.com/questions/37800195/how-do-you-load-a-groovy-file-and-execute-it

Example.Groovy

def exampleMethod() {
println("exampleMethod")
} def otherExampleMethod() {
println("otherExampleMethod")
}
return this

JenkinsFile

node {
// Git checkout before load source the file
checkout scm // To know files are checked out or not
sh '''
ls -lhrt
''' def rootDir = pwd()
println("Current Directory: " + rootDir) // point to exact source file
def example = load "${rootDir}/Example.Groovy" example.exampleMethod()
example.otherExampleMethod()
}

shared library方式

https://jenkins.io/doc/book/pipeline/shared-libraries/

最为推荐。

As Pipeline is adopted for more and more projects in an organization, common patterns are likely to emerge. Oftentimes it is useful to share parts of Pipelines between various projects to reduce redundancies and keep code "DRY"

https://stackoverflow.com/questions/38695237/create-resusable-jenkins-pipeline-script?noredirect=1

The Shared Libraries (docs) allows you to make your code accessible to all your pipeline scripts. You don't have to build a plugin for that and you don't have to restart Jenkins.

E.g. this is my library and this a Jenkinsfile that calls this common function.

The global library can be configured through the following means:

  • an @Library('github.com/...') annotation in the Jenkinsfile pointing to the URL of the shared library repo.
  • configured on the folder level of Jenkins jobs.
  • configured in Jenkins configuration as global library, with the advantage that the code is trusted, i.e., not subject to script security.

A mix of the first and last method would be a not explicitly loaded shared library that is then requested only using its name in the Jenkinsfile: @Library('mysharedlib').

Jenkins pipeline shared library的更多相关文章

  1. Jenkins Pipeline 参数详解

    Pipeline 是什么 Jenkins Pipeline 实际上是基于 Groovy 实现的 CI/CD 领域特定语言(DSL),主要分为两类,一类叫做 Declarative Pipeline,一 ...

  2. jenkins pipeline的声明式与脚本式

    自从Jenkins 2.0 版本升级之后,支持了通过代码(Groovy DSL)来描述一个构建流水线,灵活方便地实现持续交付,大大提升 Jenkins Job 维护的效率,实现从 CI 到 CD 到转 ...

  3. eclipse报错:Failed to load the JNI shared library

    Eclipse运行时提示“Failed to load the JNI shared library /Java/jre6/bin/client/jvm.dll”的一个解决方案 因为 Eclipse ...

  4. Eclipse - Failed to load the JNI shared Library (JDK)

    When I try opening Eclipse, a pop-up dialog states: Failed to load the JNI shared library "C:/J ...

  5. Linux Programe/Dynamic Shared Library Entry/Exit Point && Glibc Entry Point/Function

    目录 . 引言 . C/C++运行库 . 静态Glibc && 可执行文件 入口/终止函数 . 动态Glibc && 可执行文件 入口/终止函数 . 静态Glibc & ...

  6. 启动Eclipse 弹出"Failed to load the JNI shared library jvm.dll"错误

    启动Eclipse 弹出"Failed to load the JNI shared library jvm.dll"错误,如下 原因:eclipse的版本与jre或者jdk版本不 ...

  7. dynamic-link library shared library of functions and resources

    https://msdn.microsoft.com/en-us/library/1ez7dh12.aspx A dynamic-link library (DLL) is an executable ...

  8. Eclipse:启动时提示"Failed to load the JNI shared library"的解决方案

    今天打开Eclipse,弹出提示框"Failed to load the JNI shared library" 原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jr ...

  9. 64位操作系统弹出"Failed to load the JNI shared library “E:/2000/Java/JDK6/bin/..jre/bin/client/jvm.dll”

    64位操作系统弹出"Failed to load the JNI shared library /..jre/bin/client/jvm.dll”,最大的可能就是jdk的版本问题.去你的C ...

随机推荐

  1. CSS居中的几种方式总结

    1.水平居中的 margin:0 auto; 这个是用于子元素上的,前提是不受float影响 <style type="text/css"> .box{ width: ...

  2. ELK部署详解--kibana

    kibana.yml # Kibana is served by a back end server. This setting specifies the port to use.#端口server ...

  3. 关于Ubuntu18.04谷歌浏览器经常卡死的解决

    老电脑本来用的是Win系列,后来改成Linux后就不卡了,这几天同Notebook运行的Script开始复杂了,Ubuntu经常卡死(发公众号也经常卡死),本来以为是Ubuntu的问题 后来一想,不对 ...

  4. vue $emit 用法

    1.父组件可以用props传递给子组件. 2.子组件可以利用$emit触发父组件事件. vm.$emit('父组件方法',参数); vm.$on(event,fn); $on监听event事件后运行f ...

  5. 封装一个基于NLog+NLog.Mongo的日志记录工具类LogUtil,nloglogutil

    封装一个基于NLog+NLog.Mongo的日志记录工具类LogUtil,代码比较简单,主要是把MongoTarget的配置.FileTarget的配置集成到类中,同时利用缓存依赖来判断是否需要重新创 ...

  6. (转)ZooKeeper的Znode剖析

    ZooKeeper的Znode剖析 https://blog.csdn.net/lihao21/article/details/51810395 根据节点的存活时间,可以对节点划分为持久节点和临时节点 ...

  7. C# Winfom 中ListBox的简单用法

    https://www.cnblogs.com/xielong/p/6744805.html Winform控件ListBox的用法 1.如何添加listBox的值 this.listBox1.Ite ...

  8. CAS (多线程保证原子性)

    面试必问的CAS,你懂了吗? 置顶 2018年03月14日 22:29:19 程序员囧辉 阅读数:29612   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csd ...

  9. 第十二节、尺度不变特征(SIFT)

    上一节中,我们介绍了Harris角点检测.角点在图像旋转的情况下也可以检测到,但是如果减小(或者增加)图像的大小,可能会丢失图像的某些部分,甚至导致检测到的角点发生改变.这样的损失现象需要一种与图像比 ...

  10. C++基础知识--DAY4

    今天主要讲的是类中除了构造器析构器以外的拷贝构造器,运算符重载等问题 首先是拷贝构造器 1. copy constructor(拷贝构造) 其也是构造器,其地位和constructor的地位是一样的 ...