为什么要使用pipeline
代码:pipeline 以代码的形式实现,通过被捡入源代码控制, 使团队能够编译,审查和迭代其cd流程
可连续性:jenkins 重启 或者中断后都不会影响pipeline job
停顿:pipeline 可以选择停止并等待人工输入或者批准,然后在继续pipeline运行
多功能:pipeline 支持现实世界的复杂CD要求, 包括fork、join子进程,循环和并行执行工作的能力
可扩展:pipeline 插件支持其DSL的自动扩展以及其插件集成的多个选项。
Pipeline的几个基本概念:
Stage: 阶段,一个Pipeline可以划分为若干个Stage,每个Stage代表一组操作。注意,Stage是一个逻辑分组的概念,可以跨多个Node。
Node: 节点,一个Node就是一个Jenkins节点,或者是Master,或者是slave,是执行Step的具体运行期环境。
Step: 步骤,Step是最基本的操作单元,小到创建一个目录,大到构建一个Docker镜像,由各类Jenkins Plugin提供
新建pipeline项目
简单配置一下这里,执行
结果

增加步骤
node(){
stage('第一步'){
echo '拉代码'
}
stage('第二步'){
echo '编译'
}
stage('第三步'){
echo '打包'
}
stage('第四步'){
echo '发布'
}
}
安装Blue Ocean 插件
安装有些错误是因为blueocean-rest 没有安装,成功安装会有Blue Ocean图标

可以更好的查看流水线

input中断
node(){
stage('第一步'){
echo '拉代码'
}
stage('第二步'){
echo '编译'
}
stage('第三步'){
echo '打包'
}
stage('第四步'){
input '发布'
}
}

点击proceed

Blue Ocean 里也可以操作

执行脚本
node (){
stage("先看看主机名")
sh "hostname"
stage("在看看磁盘空间")
sh("df -h")
stage("拉code")
git credentialsId: '9a86b70e-5b36-4170-b370-4a695affdb36', url: 'https://gitee.com/daxiashagnxian/coding.git'
}



发送邮件

node (){
stage("先看看主机名")
sh "hostname"
stage("在看看磁盘空间")
sh("df -h")
stage("拉code")
git credentialsId: '9a86b70e-5b36-4170-b370-4a695affdb36', url: 'https://gitee.com/daxiashagnxian/coding.git'
stage('发邮件')
emailext body: '啦啦啦啦', subject: 'test', to: 'zhaocuixia666@163.com'
}
