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 theJenkinsfilepointing 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的更多相关文章
- Jenkins Pipeline 参数详解
Pipeline 是什么 Jenkins Pipeline 实际上是基于 Groovy 实现的 CI/CD 领域特定语言(DSL),主要分为两类,一类叫做 Declarative Pipeline,一 ...
- jenkins pipeline的声明式与脚本式
自从Jenkins 2.0 版本升级之后,支持了通过代码(Groovy DSL)来描述一个构建流水线,灵活方便地实现持续交付,大大提升 Jenkins Job 维护的效率,实现从 CI 到 CD 到转 ...
- eclipse报错:Failed to load the JNI shared library
Eclipse运行时提示“Failed to load the JNI shared library /Java/jre6/bin/client/jvm.dll”的一个解决方案 因为 Eclipse ...
- 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 ...
- Linux Programe/Dynamic Shared Library Entry/Exit Point && Glibc Entry Point/Function
目录 . 引言 . C/C++运行库 . 静态Glibc && 可执行文件 入口/终止函数 . 动态Glibc && 可执行文件 入口/终止函数 . 静态Glibc & ...
- 启动Eclipse 弹出"Failed to load the JNI shared library jvm.dll"错误
启动Eclipse 弹出"Failed to load the JNI shared library jvm.dll"错误,如下 原因:eclipse的版本与jre或者jdk版本不 ...
- 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 ...
- Eclipse:启动时提示"Failed to load the JNI shared library"的解决方案
今天打开Eclipse,弹出提示框"Failed to load the JNI shared library" 原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jr ...
- 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 ...
随机推荐
- 【php】php从多个数组中取出最大的值
function _arr_max($arr = []){ if(func_num_args() > 1){ $result = []; foreach(func_get_args() as $ ...
- Spring cloud config 使用gitHub或者gitee连接
1. 创建SpringCloud项目,引入对应的Spring-config-server对应的jar <dependency> <groupId>org.springframe ...
- The 2018 ACM-ICPC Asia Qingdao Regional Contest
The 2018 ACM-ICPC Asia Qingdao Regional Contest 青岛总体来说只会3题 C #include<bits/stdc++.h> using nam ...
- Spring 声明式事务
事务的特性/概念 事务:一组操作要么都成功要么失败: 事务的四个关键属性(ACID): 原子性(atomicity):“原子”的本意是“不可再分”,事务的原子性表现为一个事务中涉及到的多个操作在逻辑上 ...
- Manjaro下Steam无法启动
问题描述 直接在桌面环境运行Steam,不会出现任何反应,甚至没有闪过一个对话框. 在终端中运行Sterm,出现以下提示 Repairing installation, linking /home/z ...
- bzoj4566 找相同字符
题意:给定两个字符串,从中各取一个子串使之相同,有多少种取法.允许本质相同. 解:建立广义后缀自动机,对于每个串,分别统计cnt,之后每个点的cnt乘起来.记得开long long #include ...
- python描述器
描述器定义 python中,一个类实现了__get__,__set__,__delete__,三个方法中的任何一个方法就是描述器,仅实现__get__方法就是非数据描述器,同时实现__get__,__ ...
- RGBColorspace 与 GRAYColorspace 图片混合后,生成的视频有点问题
最近有一个用户遇到一个情况: 有3张图片,其中前两张是 RGBColorspace,最后一张是 GrayColorspace: 生成的视频,在显示最后一张图片的时候,明显出现奇怪的色彩区域,看下图: ...
- c++ sort
老是搞混 return bool eg. bool cmp(node a,node b) { if (a.score==b.score) ; else return a.score>b.scor ...
- echart折线区域图
在引入echart区域折线图时,没有出现对应的区域图 当发现引入下面代码到自己的代码中并没有对应的区域图 option = { xAxis: { type: 'category', boundaryG ...