jenkins学习笔记-官网翻译
来源:互联网 发布:网络语言暴力工作视频 编辑:程序博客网 时间:2024/05/16 00:40
目录
运行多个步骤...1
Linxu系统,bsd系统,Mac系统...1
Windows系统...2
超时,重试等等...2
本章小结:...4
运行多个步骤
通道是由多个步骤组成的,通过这些步骤你可以构建,测试,部署应用。Jenkins通道允许用简单的方式来组合这多个步骤,以便帮助你模块化任何类型的自动化构建过程。
“步骤”可以类比为一个执行单个命令的单一动作。当一个步骤成功执行之后,就会跳到下一个步骤。当一个步骤执行失败,通道就失败了。
当通道里的所有步骤都执行成功,那么就可以认为是通道执行成功了。
Linxu系统,bsd系统,Mac系统
在linux,bsd和mac(unix系列)的操作系统上,sh步骤被用于在通道中执行shell命令。
Jenkinsfile(Declarative Pipeline)
pipeline {
agent any
stages {
stage('Build') {
steps {
sh'echo "Hello World"'
sh'''
echo "Multiline shellsteps works too"
ls -lah
'''
}
}
}
}
Toggle Scripted Pipeline (高级)
Jenkinsfile(Scripted Pipeline)
node {
stage('Build') {
sh'echo "Hello World"'
sh'''
echo "Multiline shell stepsworks too"
ls -lah
'''
}
}
Windows系统
基于windows的操作系统应该使用bat步骤来用于执行批量命令
Jenkinsfile(Declarative Pipeline)
pipeline {
agent any
stages {
stage('Build') {
steps {
bat'set'
}
}
}
}
Toggle Scripted Pipeline (高级)
Jenkinsfile(Scripted Pipeline)
node {
stage('Build') {
bat'set'
}
}
超时,重试等等
有一些有效的步骤来包裹其他步骤。这些有效的步骤能轻易解决诸如成功前重试和超时退出等问题
Jenkinsfile(Declarative Pipeline)
pipeline {
agent any
stages {
stage('Deploy') {
steps {
retry(3) {
sh'./flakey-deploy.sh'
}
timeout(time:3,unit:'MINUTES') {
sh'./health-check.sh'
}
}
}
}
}
ToggleScripted Pipeline (Advanced)
Jenkinsfile (Scripted Pipeline)
node {
stage('Deploy') {
retry(3) {
sh'./flakey-deploy.sh'
}
timeout(time:3,unit:'MINUTES') {
sh'./health-check.sh'
}
}
}
“Deploy”(部署)阶段重试./flakey-deploy.sh脚本三遍,然后给/health-check.sh脚本执行三分钟。如果health-check.sh三分钟内没有执行完毕,通道就会标记“Deploy”阶段执行失败。
“Wrapper”(嵌套)步骤比如超时和重试,可能包含其他的步骤,包括超时和重试步骤。
你可以将这些步骤组合起来。比如,如果我们想重试我们的部署五次,但该阶段失败之前的总花费时长又不想超过三分钟。
Jenkinsfile(Declarative Pipeline)
pipeline {
agent any
stages {
stage('Deploy') {
steps {
timeout(time:3,unit:'MINUTES') {
retry(5) {
sh'./flakey-deploy.sh'
}
}
}
}
}
}
Toggle Scripted Pipeline (高级)
Jenkinsfile(Scripted Pipeline)
node {
stage('Deploy') {
timeout(time:3,unit:'MINUTES') {
retry(5) {
sh'./flakey-deploy.sh'
}
}
}
}
本章小结:
当通道已经结束执行,你可能需要运行clean-up(清理)步骤或者执行一些基于通道输出的动作。这些动作可以在post部分执行。
Jenkinsfile(Declarative Pipeline)
pipeline {
agent any
stages {
stage('Test') {
steps {
sh'echo "Fail!"; exit 1'
}
}
}
post {
always {
echo'This will always run'
}
success {
echo'This will run only if successful'
}
failure {
echo'This will run only if failed'
}
unstable {
echo'This will run only if the run was marked as unstable'
}
changed {
echo'This will run only if the state of the Pipeline haschanged'
echo'For example, if the Pipeline was previously failing butis now successful'
}
}
}
Toggle Scripted Pipeline (高级)
Jenkinsfile(Scripted Pipeline)
node {
try {
stage('Test') {
sh'echo "Fail!"; exit 1'
}
echo'This will run only if successful'
}catch (e) {
echo'This will run only if failed'
// Since we'recatching the exception in order to report on it,
// we need tore-throw it, to ensure that the build is marked as failed
throw e
}finally {
def currentResult = currentBuild.result ?: 'SUCCESS'
if (currentResult == 'UNSTABLE') {
echo'This will run only if the run was marked as unstable'
}
def previousResult =currentBuild.previousBuild?.result
if (previousResult != null && previousResult !=currentResult) {
echo'This will run only if the state of the Pipeline haschanged'
echo'For example, if the Pipeline was previously failing butis now successful'
}
echo'This will always run'
}
}
- jenkins学习笔记-官网翻译
- jenkins 学习笔记
- Jenkins学习笔记(一)
- Jenkins学习笔记
- Jenkins---------------------学习笔记汇总
- jenkins学习笔记1
- jenkins 学习笔记
- Jenkins 使用学习笔记
- Android Material Design 官网翻译学习笔记(开篇)
- Jenkins 学习笔记(二)
- jenkins学习笔记---问题总结
- jenkins学习笔记-6-部署
- openshift 学习笔记-4 Jenkins
- 一、Jenkins学习笔记——Jenkins是啥么?
- 二、Jenkins 学习笔记——Jenkins 安装
- git、maven、jenkins学习随手笔记
- jenkins学习笔记-2-定义运行环境
- jenkins学习笔记-3-使用环境变量
- 关于Collections类的一些操作
- Python偶遇Mysql乱码解决方案
- Python2.7和3.5双版本共存和pip的使用
- Mp4文件播放原理分析
- protobuf【1】详细的安装和使用(windows cpp)
- jenkins学习笔记-官网翻译
- 快速排序的Java实现、性能分析以及适用场景
- 快速幂 O(logn)
- Android热修复—阿里的新一代热修复技术Sophix
- webView怎么保存设置Cookie
- jQuery.swiper插件
- 2017.8.18------树状数组+离散+逆序
- iOS 强制屏幕实现旋转功能,超级简单。
- 一个完整的ajax请求