Jenkins pipeline shared library

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‘).

原文地址:https://www.cnblogs.com/lightsong/p/8439277.html

时间: 2024-08-30 16:39:21

Jenkins pipeline shared library的相关文章

jenkins pipeline maven 使用

pipeline { /* * Run everything on an existing agent configured with a label 'docker'. * This agent will need docker, git and a jdk installed at a minimum. */ agent { node { label 'docker' } } // using the Timestamper plugin we can add timestamps to t

Jenkins Pipeline 参数详解

Pipeline 是什么 Jenkins Pipeline 实际上是基于 Groovy 实现的 CI/CD 领域特定语言(DSL),主要分为两类,一类叫做 Declarative Pipeline,一类叫做 Scripted Pipeline. Declarative Pipeline 体验上更接近于我们熟知的 travis CI 的 travis.yml,通过声明自己要做的事情来规范流程,形如: pipeline { agent any stages { stage('Build') { st

【已解决】运行Eclipse出错:Failed toload the JNI shared library

[问题] 运行Android的ADT,即Eclipse出错: Failed to load the JNIshared library C:\Program Files(x86)\Java\jre6\bin\client\jvm.dll 其中背景是: 1.之前已经可以正常运行的,即已经正常安装了JRE6的. 2.后来删除掉了JRE6了. 3.刚刚又去重新安装了JRE6,结果还是错误依旧. 4.并且已经确定了:C:\ProgramFiles (x86)\Java\jre6\bin\client\j

启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!

启动 Eclipse 弹出"Failed to load the JNI shared library jvm.dll"错误的解决方法 http://blog.csdn.net/zyz511919766/article/details/7442633   原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者jdk并配置好环境变量.(2)copy一个jvm.dll放在该目录下. 原因2:eclipse的版本与jre或者jdk版本不一致 对策:要么两者都安装64位的,要

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 file that acts as a shared library of functions and resources. Dynamic linking enables an executable to call functions or use resources stored in a s

Qt学习之路(60): 创建shared library

前段时间说了Qt一些类库的使用,今天来换一下口味,来看一下程序设计的问题.今天来说的是关于共享库 shared library. 如果你打开一些 Windows 应用程序的目录,你会发现有很多程序的 exe 文件都很小,大约几百K 的样子,并且目录中不仅仅只有一个 exe 文件,还包含着一大堆 dll 文件.这些 dll 其实就是一些共享库,所谓共享库,其实就是一些动态链接库,能够由程序在运行时进行动态加载的库.既然说是共享,那就是说,这些库不仅仅自己的程序可以使用,并且其他程序也可以使用,例如

eclipse-failed to load the JNI shared library

很久没有用eclipse,刚才打开,提示:failed to load the jni shared library.这个问题一般是eclipse和JDK位数不一样. 解决方案: 1,在cmd中输入[java -version] 在这里,画线部分是Client VM表示是32位的jdk.若是64-bit Server,表示64位jdk. 2,打开eclipse安装目录 记事本方式打开eclipse.ini.我用sublime打开的.如下图.划红线处,是win32.x86表示32位.win32.x

启动Eclipse 弹出“Failed to load the JNI shared library”错误的解决方法

原因1:eclipse的版本与jre或者jdk版本不一致 对策:要么两者都安装64位的,要么都安两个是32位一个是64位. 原因2:给定目录下jvm.dll不存在 对策:(1)重新安装jre或者jdk并配置好环境变量.(2)copy一个jvm.dll放在该目录下. 原因1的概率更大一些,原因2不太可能发生. 启动Eclipse 弹出"Failed to load the JNI shared library"错误的解决方法,布布扣,bubuko.com

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

出现这个问题的一个原因是eclipse需要的32位jdk,你的环境变量中配的是64位jdk 于是有人建议,重装个32位的jdk,把环境变量换成32位的jdk,但如果你的其它程序需要64位jdk的话,这肯定不是一个好办法 还有一种方法是在 eclipse根目录下有个eclipse.ini文件,添加个 -vm参数 -vm C:/Java32/jdk1.7.0_45/bin/javaw.exe      //这是我的32位jdk 注意位置 -startup plugins/org.eclipse.eq