jenkins教程:jenkinsfile语法之parameters、triggers
parameters
parameters
指令定义 pipeline的专有参数列表,支持参数类型:
string
:字符串类型text
:文本, 可包括多行booleanParam
:布尔参数choice
:choice 参数password
:密码参数
示例脚本:
pipeline {
agent any
parameters {
string(name: 'DEPLOY_ENV', defaultValue: 'staging', description: '')
text(name: 'DEPLOY_TEXT', defaultValue: 'One\nTwo\nThree\n', description: '')
booleanParam(name: 'DEBUG_BUILD', defaultValue: true, description: '')
choice(name: 'CHOICES', choices: ['one', 'two', 'three'], description: '')
password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'A secret password')
}
stages {
stage('Example') {
steps {
echo "${params.DEPLOY_ENV}"
echo "${params.PASSWORD}"
}
}
}
}
triggers
triggers
指令定义了 Pipeline自动化触发的方式,主要包括3种触发器:
cron
:接受一个cron样式的字符串来定义 Pipeline触发的间隔周期,例如:triggers { cron('H */4 * * 1-5') }
pollSCM
:接受一个cron样式的字符串来定义 Jenkins检查SCM源码更新的常规间隔;如果存在新的更改,Pipeline将被重新触发。例如:triggers { pollSCM('H */4 * * 1-5') }
upstream
:接受以逗号分隔的job字符串和阈值。当字符串中的任何作业以最小阈值完成时,将重新触发Pipeline。例如:triggers { upstream(upstreamProjects: 'job1,job2', threshold: hudson.model.Result.SUCCESS) }
更多cron表达式语法介绍可参考 Linux cron定时介绍。
示例脚本:
pipeline {
agent any
triggers {
cron('H */4 * * 1-5')
}
stages {
stage('init') {
steps {
echo 'Hello World'
}
}
}
}
links:
https://devtest-notes.readthedocs.io/zh/latest/CI/continuous-integration-for-jenkins-pipeline.html