我就纳闷了,铺天盖地的各种jenkins实操,咋就没有面向白白授人以鱼,快速上手的简单指导呢?自己整理如下:
slave概念:slave需要添加,它是用来干嘛的?它或它们可能是一台服务器,采用jenkins母机对其们进行构建和部署及配置
blue ocean:插件之一,需要jenkins2.7.x以上版本。
同类软件:hudson,bamboo。teamcity。travisci。
cloudbees学习网站,一站式学习,非常经典
https://premium.cbu.cloudbees.com/cloudbees-university-jenkins-pipeline-fundamentals
https://premium.cbu.cloudbees.com/cloudbees-university-jenkins-fundamentals
https://jenkins.io/doc/pipeline/examples/
jenkinsfile语法:https://jenkins.io/doc/book/pipeline/syntax
jenkins命令:https://jenkins.io/doc/book/pipeline/syntax/
jenkins的那些命令哪儿来的?在这里:https://jenkins.io/doc/pipeline/steps/
pipline特点:
1.master可以重启,pipeline不受影响
2.可暂停
两种:
declarative pipeline:
较新
agent指定slave(declarative采用node指定slave)
严格的语法结构,对groovy要求不高
blueocean生成流水线
script pipeline
1.比较豪放,对groovy要求略高
采用node指定slave
3.Scripted Pipeline code must explicitly handle the checkout scm step,脚本流水线必须显示的执行checkout scm步骤
语言,Uses a DSL based on Apache Groovy ,"DSL" (Domain Scripting Language)
blueocean用法:在jenkins传统界面的左侧有一个打开blueocean(这个是插件安装上去的),打开后进入到blueocean的界面,里面可以点击添加流水线,可以选种类
jenkins规则:
1.slave/agent,一般非特殊情况,命令在这其上执行
2.jenkins构建的包会保留在工作空间内,除主动删除外永久保留
3.parallel:Each "parallelized branch" is a stage A stage can use either steps or parallel at the top level; it cannot use both A stage within a parallel stage can contain agent and steps sections A parallel stage cannot contain agent or tools Add failfast true to force all parallel process to abort if one fails
pipeline和multibranchpipeline
1.优选multibranchpipeline,why???
2.blueocean创建的pipeline全部都是multibranch的
3.multibranch可以为新分支直接创建流程
4.当git的分支被删除时,对应的role也会被删除
5.可以覆盖父任务的设置,即个性定制
agent:
1.agent any,可以在任意一个agent上执行;
2.agent none,写在全局的位置,表示每个stage可以定义自己的agent
3.当在step里时,当有需要在agent上执行的命令时不能使用agent none,废话……
4.agent {label 'xxxx'},很重要,指定用哪个agent
5.agent指定docker镜像或者dockerfile,只能用于multibranch pipline: pipeline { agent { docker 'bzzzcentos:7' } .... }
pipeline { agent none stages { stage ('Build') { agent { label 'bzzzmaven' } steps { ... } } stage ('Deploy') { agent { label 'bzzzproduction' } steps { ... } } } }
6.script方式的:node('xxx'){container('ccccc'){checkout scm stage 'vvvv'{}}}
技巧:
1.可以使用blueocean界面编辑方式生成一个大概的脚本,细节的再具体调试
1.jenkins代码生成应用,就在jenkins内,当创建流水线的时候里面有个链接叫pipeline-syntax:https://dso.ci.kingland.cc/job/ami-update/pipeline-syntax/
2.创建pipeline的时候有definition选项,有俩,一个叫pipeline script from SCM表示从git库拉取jenkinsfile,一个叫pipeline scrip,选择这个后就可以在下面弹出代码框进行编辑(保存后或者执行后是否会在git库中同时生成一个jenkinsfile?)
3.优选multibranch pipline的方式
4.multipipeline的设置,第一级项目设置的进入方法:项目总览页,项目名称旁边有个齿轮设置按钮,进入后左侧有个config。
5.agent(node)可以定义在全局,也可以定义在每个stage内
jenlkins 中k8s配置:在管理界面的系统配置里,添加云服务,俩选项,一个是java一个是k8s,选择k8s后一路向下可以看见有一个pod template选项,点开后即可看见一个标准的pod的镜像参数。即可
agent或者node的设置:https://jenkins.io/doc/book/pipeline/docker/
区别是声明式的是单独的agent{}用在stage下,并且和step{}同级,脚本式的是在stage里的docker.image('').inside{xxxxxx}
宣明式jenkinsfile常用命令:
1.environment: 配置变量,用于stage内或者全局
2.option:
3.parameters: 在全局声明parameters,在stage内引用时使用${params.xx}调用
4.triggers:
脚本式jenkinsfile常用命令:
1.if else
2.try catch finally