jenkins pipline 和 jenkinsfile
Jenkins Pipeline(或简称为 "Pipeline")是一套插件,将持续交付的实现和实施集成到 Jenkins 中。
Jenkins Pipeline 提供了一套可扩展的工具,用于将“简单到复杂”的交付流程实现为“持续交付即代码”。Jenkins Pipeline 的定义通常被写入到一个文本文件(称为Jenkinsfile)中,该文件可以被放入项目的源代码控制库中。
Jenkinsfile 是 Jenkins 2.x 核心特性 Pipeline 的脚本,由Groovy语言实现。
jenkinsfile 能使用两种语法进行编写 - 声明式和脚本化。
声明式和脚本化的流水线从根本上是不同的。 声明式流水线的是 Jenkins 流水线更近的特性:
a.相比脚本化的流水线语法,它提供更丰富的语法特性,
b.是为了使编写和读取流水线代码更容易而设计的。
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
stages {
stage('Build') {
steps {
//
}
}
stage('Test') {
steps {
//
}
}
stage('Deploy') {
steps {
//
}
}
}
}
Jenkinsfile (Scripted Pipeline)
node {
stage('Build') {
//
}
stage('Test') {
//
}
stage('Deploy') {
//
}
}
下面将以声明式脚本为例,介绍jenkinsfile:
#设置运行的agent
pipeline {
agent {label 'jenkins-slave'} // 配置构建项目在标签为jenkins-slave的机器上运行
.....
使用多个agent
pipeline {
agent none
stages {
stage('Build') {
agent any
steps {
echo "build..."
}
}
stage('Test on Linux') {
agent {
label 'linux'
}
steps {
echo "test..."
}
配置可选参数
agent any
options{
disableConcurrentBuilds() //不允许同时执行流水线
skipDefaultCheckout() //默认跳过来自源代码控制的代码
timeout(time: 10, unit: 'MINUTES') //设置流水线运行的超时时间
timestamps() //预定义由Pipeline生成的所有控制台输出时间
}
配置机密文本、用户名和密码
stage('Deploy'){
steps {
withCredentials([usernamePassword(credentialsId: 'aliyun_oss_upload', passwordVariable: 'aliyun_sceret', usernameVariable: 'aliyun_key')]) {
sh '~/ossutil config -e ${endpoint} -i ${aliyun_key} -k ${aliyun_sceret};~/ossutil cp -r -f dist "oss://${name}"'
}}}
注:需先在jenkins添加用户凭据
拉取代码
stage('Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/${branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '3', url: 'ssh://git@giturl/javacode.git']]])
}
}
#在job中点击Pipline Syntax ,选择checkout out from version control ,选择git输入仓库地址,生成拉取代码配置
定义构建完成后执行动作
post {
success {
echo '构建成功'
}
failure {
echo '构建失败'
}
unstable {
echo '该任务被标记为不稳定任务'
}
aborted {
echo '该任务被终止'
}
}
条件判断
stage('Build'){
steps {
script {
if ("${gitrepo}" == "java") {
echo "java"
}
else if ("${gitrepo}" == "python"){
echo "python"
} else {
echo "nodejs"
}
}
}
}
#if 需定义在script{}内
获取命令返回值
stage('Push'){
steps {
script{
def pid = sh returnStatus: true, script: " ps -ef|grep tomcat|awk '{print \$2}'"
echo '$pid'
}
}
}
jenkins pipline 和 jenkinsfile的更多相关文章
- jenkins pipline和jenkinsfile
Jenkins Pipeline(或简称为 "Pipeline")是一套插件,将持续交付的实现和实施集成到 Jenkins 中. Jenkins Pipeline 提供了一套可扩展 ...
- Jenkins高级用法 - Jenkinsfile 介绍及实战经验
系列目录 1.Jenkins 安装 2.Jenkins 集群 3.Jenkins 持续集成 - ASP.NET Core 持续集成(Docker&自由风格&Jenkinsfile) 4 ...
- jenkins pipline 几个注意细节
新建jenkins pipline 1)pipeline的脚本语法要正确,sonarqube的projectKey需要做相应的修改 2)先执行一次构建,会报错 3)进到jenkins workspac ...
- 持续集成工具之Jenkins pipline简单示例
前文我们主要聊了下jenkins的插件安装.用户及权限管理.邮件发送.配置凭证到gitlab上拉取项目和创建普通job:回顾请参考https://www.cnblogs.com/qiuhom-1874 ...
- ubuntu 16.04 jenkins pipline的实现 最终docker启动服务
准备工作:两台虚拟机A:192.168.1.60 B:192.168.1.61 C:一个存放代码的代码库(github)A:jenkins git docker openssh-server(ssh) ...
- 使用Jenkins+Pipline 持构建自动化部署之安卓源码打包、测试、邮件通知
一.引言 Jenkins 2.x的精髓是Pipeline as Code,那为什么要用Pipeline呢?jenkins1.0也能实现自动化构建,但Pipeline能够将以前project中的配置信息 ...
- jenkins:实现Jenkinsfile与Json的转换
实现Jenkinsfile与Json的转换 目录 实现Jenkinsfile与Json的转换 方法1:使用现有的jenkins插件 参考 方法2:解析原生的jenkinsfile文件 参考 最近在做个 ...
- jenkins pipline 发送邮件
推荐一个好网站https://www.w3cschool.cn/jenkins/jenkins-e7bo28ol.html 获取git 用户信息// Get checkout output value ...
- Jenkins Pipline语法
引用自:http://baijiahao.baidu.com/s?id=1582812185263227836&wfr=spider&for=pc 引用自:https://www.cn ...
随机推荐
- 【Android-NetWork】 判断是否连接网络,判断网络连接方式
如何判断Android是否连接网络? Java代码: ConnectivityManager conn = (ConnectivityManager) getSystemService(Activit ...
- java服务宕机原因查询
背景 在java服务项目上线之后经常会出现宕机的情况 常见原因 内存溢出 1.查到服务进程号 [root@wms ~]# ps -ef|grep java root 6399 6069 0 08:57 ...
- .net大文件传输断点续传源码
IE的自带下载功能中没有断点续传功能,要实现断点续传功能,需要用到HTTP协议中鲜为人知的几个响应头和请求头. 一. 两个必要响应头Accept-Ranges.ETag 客户端每次提交下载请求时,服务 ...
- 51 Nod 1092 回文字符串
1092 回文字符串 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串.每 ...
- Jmeter(六)关联之XPath提取器
如果请求返回的消息为xml或html格式的,可以用XPath提取器来提取需要的数据 以http://www.weather.com.cn/为例: 先新建一个HTTP请求GetCityURL,获取城市天 ...
- PHP-windows下IDEA配置网页地址
- python数据可视化示例柱状图
from matplotlib import pyplot as plt import platform import pandas from pathlib import Path # 根据不同的平 ...
- HDX Insight Installation & Configuration
NetScaler Insight Center 11.1 Installation & Configuration NetScaler Insight Center 11.0 Insta ...
- 统计网络time_wait连接状态及tcpip连接数
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' LAST_ACK 1 SYN_RECV 14 ESTABLIS ...
- leetcode-hard-array-128. Longest Consecutive Sequence
mycode 92.62% class Solution(object): def longestConsecutive(self, nums): """ :type ...