标签:val 步骤 https success when 节点 return pre nested
Declarative Pipeline中有效的基本语句和表达式遵循与Groovy语法相同的规则?,但有以下例外:
作用:告知Jenkins选择那台节点机器去执行Pipeline代码。这个指令是必要的
any---任何
none---管道不指定,模块,步骤中指定
label---指定标签
node
docker
dockerfile
kubernetes
作用:一般用来发送消息,或者邮件通知。
在post代码块区域,支持多种条件指令,这些指令有always,changed,failure,success,unstable,和aborted。
在一个Declarative Pipeline脚本中,允许出现至少一次stages。一个stages下可以包含多个stage,一个stage 下至少有一个steps。
在Declarative 模式中,只支持steps,不支持在steps {…} 里面嵌套写step{…}。
pipeline {
agent any
stages {
stage(‘Build‘) {
steps {
println "Build"
}
}
stage(‘Test‘) {
steps {
println "Test"
}
}
stage(‘Deploy‘) {
steps {
println "Deploy"
}
}
}
}
environment设置环境变量
options内置的选项
parameters参数,可通过页面配置
triggers触发器,可通过页面配置
tool定义自动安装和放置工具的部分PATH。如果agent none指定,这将被忽略。
特点:只支持定义maven jdk gradle三种工具的环境变量。
input---等待用户输入,根据输入值继续后续的流程
when----符合条件,则执行
pipeline {
agent any
environment {
quick_test = false
}
stages {
stage(‘Example Build‘) {
steps {
script {
echo ‘Hello World‘
}
}
}
stage(‘Example Deploy‘) {
when {
expression {
return (quick_test == “true” )
}
}
steps {
echo ‘Deploying‘
}
}
}
}
顺序stage
pipeline {
agent none
stages {
stage(‘Non-Sequential Stage‘) {
agent {
label ‘for-non-sequential‘
}
steps {
echo "On Non-Sequential Stage"
}
}
stage(‘Sequential‘) {
agent {
label ‘for-sequential‘
}
environment {
FOR_SEQUENTIAL = "some-value"
}
stages {
stage(‘In Sequential 1‘) {
steps {
echo "In Sequential 1"
}
}
stage(‘In Sequential 2‘) {
steps {
echo "In Sequential 2"
}
}
stage(‘Parallel In Sequential‘) {
parallel {
stage(‘In Parallel 1‘) {
steps {
echo "In Parallel 1"
}
}
stage(‘In Parallel 2‘) {
steps {
echo "In Parallel 2"
}
}
}
}
}
}
}
}
并行stage
failFast true,只要有一个不通过,就中止运行pipeline下面的代码
pipeline {
agent any
stages {
stage(‘Non-Parallel Stage‘) {
steps {
echo ‘This stage will be executed first.‘
}
}
stage(‘Parallel Stage‘) {
when {
branch ‘master‘
}
failFast true
parallel {
stage(‘Branch A‘) {
agent {
label "for-branch-a"
}
steps {
echo "On Branch A"
}
}
stage(‘Branch B‘) {
agent {
label "for-branch-b"
}
steps {
echo "On Branch B"
}
}
stage(‘Branch C‘) {
agent {
label "for-branch-c"
}
stages {
stage(‘Nested 1‘) {
steps {
echo "In stage Nested 1 within Branch C"
}
}
stage(‘Nested 2‘) {
steps {
echo "In stage Nested 2 within Branch C"
}
}
}
}
}
}
}
}
Pipeline Basic Steps-1-方法deleteDir和dir、echo、error、fileExists、isUnix、pwd、mail、retry、leep、timeout、waitUntil、withEnv
Pipeline Basic Steps-6-readFile,写文件writeFile和git SCM
标签:val 步骤 https success when 节点 return pre nested
原文地址:https://www.cnblogs.com/liuyitan/p/12735091.html