持续交付(三)Jenkinsfile语法使用介绍

前言

本章主要讲述:Jenkinsfile语法基本介绍

上篇blog已经讲过Pipeline的操作我们都是用解释性代码Jenkinsfile来描述
且Jenkinsfile的语法形式有两种

# V2.5之后引入,结构化方式
-	1、Declarative pipeline
# 基于groovy的语法
-	2、Scripts pipeline

那本章咱们就详细讲述一下这两种语法的使用



一、Declarative pipeline基本使用

1、必须包含在一个pipeline块内,具体来说是:pipeline{}

2、基本的部分 是“steps”,steps即告诉Jenkins要做什么

3、语句分类具体包含 【Sections,Directives,Steps,赋值】 等几大类


1、agent使用

1.1、基本介绍

agent:即定义pipeline执行节点,是必须出现的指令

参数:
	--	any:可以在任意agent上执行pipeline
	
	--	none:pipeline将不分配全局agent,每个stage分配自己的agent
	
	--	label:指定运行节点的Label
	
	--	node:自定义运行节点配置
	 	-	指定label
	 	-	指定customWorkspace
	 	
	--	docker:控制目标节点上的docker运行相关内容

1.2、代码示例

# 指定运行节点为slave,工作区间为mikasaWorkspace

pipeline{
   
    agent{
   
        node{
   
            label "slave"
            customWorkspace "mikasaWorkspace"
        }
    }
}


2、[stages,stage,steps]使用

2.1、基本介绍

stages: 包含一个或多个stage的序列,Pipeline的大部分工作在此执行

  • 他是必须出现的指令
  • 无参数
  • 并且每个pipeline代码区间中必须只有一个stages

stage: 包含在stages中,pipeline完成的所有实际工作都需要包含到stage中

  • 他是必须出现的指令
  • 无参数
  • 需要定义stage的名字

你可能感兴趣的:(Jenkins,jenkins,cd)