当前位置:网站首页>Jenkins入门(二)声明式流水线Jenkins Pipeline
Jenkins入门(二)声明式流水线Jenkins Pipeline
2020-11-06 22:33:30 【超_Charles】
1. Jenkins Pipeline 基本概念
流水线是用户定义的一个CD流水线模型 。流水线的代码定义了整个的构建过程, 他通常包括构建, 测试和交付应用程序的阶段 。 Jenkins Pipeline
(或简称为"Pipeline")是一套插件,将持续交付的实现和实施集成到Jenkins中。 持续交付Pipeline
自动化的表达了这样一种流程:将基于版本控制管理的软件持续的交付。 Jenkins Pipeline 的定义通常被写入到一个Jenkinsfile
文本文件中,该文件可以被放入项目的源代码控制库中。
2.Jenkinsfile 基础语法
pipeline { // 特定语法,pipeline 块定义了整个流水线中完成的所有的工作
agent any // agent为整个流水线分配一个执行器 (在节点上)和工作区
stages { // 所有流程(状态)的外层块,仅有一个
stage('Build') { // 每个stage为一流程,定义名称
steps { // 步骤块,内部包含具体操作
sh 'make' // sh操作,其引号间的文字会当成shell直接执行
}
}
stage('Test'){
steps {
sh 'make check'
junit 'reports/**/*.xml' //junit使用匹配的定义测试xml进行单元测试
}
}
stage('Deploy') {
steps {
sh 'make publish'
}
}
}
}
3.创建 Hello World 流水线
- 登录
Jenkins
,新建任务(New Item),选择流水线
,输入工程名称Hello Pipeline
,确定。 - 填写描述,勾选
参数化构建过程(This project is parameterized)
。 - 添加参数,选择
字符参数(String parameter)
,并设置这个字符串参数(名称,默认值,描述),这样我们在Jenkinsfile中就可以取到这个值了。 - 向下滑动到
流水线
,定义选择Pipeline script
,脚本输入如下内容,然后保存。
pipeline {
agent any
environment { //环境变量
GREETING="Hello"
}
stages{
stage('打招呼') {
steps{
sh 'echo "$GREETING $TITLE"'
}
}
}
post { //构建完成后置操作
aborted { //如果构建中断,则执行
echo '构建被中止!'
}
success { //构建成功执行
echo '构建成功!'
}
failure { //构建失败执行
echo '构建失败!'
}
}
}
-
点击
Build with Parameters(参数化构建)
,然后开始构建
。 -
构建完成输出界面:
-
把鼠标放在打招呼下边的绿色框上,点出现的
logs
,可以看到输出了预期的值。 -
找到左下角的
Build History(构建历史)
的构建版本号,如当前是#1
,点进去,选择Console Output
查看详细的执行日志。
# 成功Console Output
Started by user charles
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /home/jenkins/root/workspace/Hello Pipeline
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (打招呼)
[Pipeline] sh
+ echo 'Hello Jenkins Pipeline'
Hello Jenkins Pipeline
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] echo
构建成功!
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
版权声明
本文为[超_Charles]所创,转载请带上原文链接,感谢
https://my.oschina.net/chaoo/blog/4703690
边栏推荐
- C++ 数字、string和char*的转换
- C++学习——centos7上部署C++开发环境
- C++学习——一步步学会写Makefile
- C++学习——临时对象的产生与优化
- C++学习——对象的引用的用法
- C++编程经验(6):使用C++风格的类型转换
- Won the CKA + CKS certificate with the highest gold content in kubernetes in 31 days!
- C + + number, string and char * conversion
- C + + Learning -- capacity() and resize() in C + +
- C + + Learning -- about code performance optimization
猜你喜欢
-
C + + programming experience (6): using C + + style type conversion
-
Latest party and government work report ppt - Park ppt
-
在线身份证号码提取生日工具
-
Online ID number extraction birthday tool
-
️野指针?悬空指针?️ 一文带你搞懂!
-
Field pointer? Dangling pointer? This article will help you understand!
-
HCNA Routing&Switching之GVRP
-
GVRP of hcna Routing & Switching
-
Seq2Seq实现闲聊机器人
-
【闲聊机器人】seq2seq模型的原理
随机推荐
- LeetCode 91. 解码方法
- Seq2seq implements chat robot
- [chat robot] principle of seq2seq model
- Leetcode 91. Decoding method
- HCNA Routing&Switching之GVRP
- GVRP of hcna Routing & Switching
- HDU7016 Random Walk 2
- [Code+#1]Yazid 的新生舞会
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- HDU7016 Random Walk 2
- [code + 1] Yazid's freshman ball
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- Qt Creator 自动补齐变慢的解决
- HALCON 20.11:如何处理标定助手品质问题
- HALCON 20.11:标定助手使用注意事项
- Solution of QT creator's automatic replenishment slowing down
- Halcon 20.11: how to deal with the quality problem of calibration assistant
- Halcon 20.11: precautions for use of calibration assistant
- “十大科学技术问题”揭晓!|青年科学家50²论坛
- "Top ten scientific and technological issues" announced| Young scientists 50 ² forum
- 求反转链表
- Reverse linked list
- js的数据类型
- JS data type
- 记一次文件读写遇到的bug
- Remember the bug encountered in reading and writing a file
- 单例模式
- Singleton mode
- 在这个 N 多编程语言争霸的世界,C++ 究竟还有没有未来?
- In this world of N programming languages, is there a future for C + +?
- es6模板字符
- js Promise
- js 数组方法 回顾
- ES6 template characters
- js Promise
- JS array method review
- 【Golang】️走进 Go 语言️ 第一课 Hello World
- [golang] go into go language lesson 1 Hello World