|
一、概念
1、什么是 pipeline
Jenkins Pipeline is a suite of plugins which 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
pipeline 是 jenkins 的一套插件,用于定义 CD 流程,弹性,可管理。
2、什么是 Jenkinsfile
通过代码的方式来管理 pipeline
这样一来,可以通过版本控制系统来管理。
3、Jenkinsfile 的内容示例
---------------------------------------------------------------------------------------
~]# cat Jenkinsfile
#!/usr/bin/env groovy
pipeline {
agent any
stages {
stage('Prepare') {
steps {
echo 'Preparing..'
echo "[+] --> Job: ${env.BUILD_URL}"
}
}
stage('Build') {
steps {
echo 'Building..'
sh 'xxx.sh build'
}
}
stage('Test') {
steps {
echo 'Testing..'
sh 'xxx.sh test'
}
}
stage('Deploy') {
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps {
echo 'Deploying....'
sh 'xxx push'
}
}
}
post {
always {
echo 'Sending....'
emailext attachLog: true, body: '$DEFAULT_CONTENT', recipientProviders: [[$class: 'DevelopersRecipientProvider']], subject: '$DEFAULT_SUBJECT'
}
}
}
---------------------------------------------------------------------------------------
4、Blue Ocean
Blue Ocean rethinks the user experience of Jenkins. Designed from the ground up for Jenkins Pipeline, but still compatible with Freestyle jobs, Blue Ocean reduces clutter and increases clarity for every member of the team.
Blue Ocean 是 jenkins 为了增强用户体验放出来的一个新的 UI 插件。
二、如何工作
1、安装插件
在插件管理页面,搜搜 pipeline 和 Blue Ocean 的关键词来安装你想要的插件。
2、创建一个任务
选择菜单:“Jenkins-新建”
------------------------------------------------------------------------------
Item名称: test_pipeline
(勾选)Pipeline
确定
【General】
项目名称: test_pipeline
参数化构建过程:
String parameter
名字: key01
默认值: default_not_exist
String parameter
名字: key02
默认值: default_not_exist
【Build Triggers】
触发远程构建 (例如,使用脚本)
身份验证令牌:test_build_token
【Pipeline】
Definition: Pipeline script from SCM (下拉菜单选择)
SCM: Subvision
Modules:
Repository URL: xxx
Credentials: xxx
Script Path: Jenkinsfile
保存
------------------------------------------------------------------------------
3、打开上述任务页面,有如下菜单
Back to Dashboard
Status
Changes
Build with Parameters
删除 Pipeline
配置
Open Blue Ocean
Full Stage View
Embeddable Build Status
Pipeline Syntax
其中,
选择: Open Blue Ocean
结果:新版本的 UI 入口。
选择: Pipeline Syntax
结果:编写 Jenkinsfile 的帮助文档(咱们重点查看这个)
进入上述页面,有一个菜单:
Back
Snippet Generator
Step Reference
Global Variables Reference
Online Documentation
IntelliJ IDEA GDSL
【 重点1: Snippet Generator 】
通过这个工具,可以自动的生成你想要的 Pipeline Script 实例,快去试试吧。(上一节提到的 Jenkinsfile 的内容示例中,最后一段发邮件的内容,我百思不得其解,后来就是这样轻易得到代码的。)
This Snippet Generator will help you learn the Pipeline Script code which can be used to define various steps. Pick a step you are interested in from the list, configure it, click Generate Pipeline Script, and you will see a Pipeline Script statement that would call the step with that configuration. You may copy and paste the whole statement into your script, or pick up just the options you care about. (Most parameters are optional and can be omitted in your script, leaving them at default values.)
【 重点2: Global Variables Reference 】
你肯定会想要用到一些全局变量,参数,那么请到这里找找文档吧。(有点遗憾的是 svn 相关的变量没找到,希望你用的是 git 来管理代码)
4、提交到代码仓库,触发构建后观察页面。
ZYXW、参考
1、Getting Started with Pipeline
https://jenkins.io/doc/book/pipeline/getting-started/
|
|