为 Jenkins 配置作为代码插件 (JCasC) 定期构建语法
Build Periodically Syntax for Jenkins Configuration as Code Plug-In (JCasC)
我正在尝试使用配置即代码 (JCasC) 插件来创建一个定期构建的管道作业,但我无法在网上的任何地方找到它的语法。我正在用 YAML 编写配置。
"Build Periodically" 字段位于管道作业中的“生成触发器”下,并且有一个名为“计划”的文本字段。我的日程安排是 0 6-19 * * *
这甚至可以做到吗?
这是我要编辑的 yaml 文件:
jobs:
- script: >
folder('test1'){
pipelineJob('test1/seedJobTest') {
description 'seedJobTest'
logRotator {
daysToKeep 10
}
definition {
cpsScm {
scm {
git {
remote {
credentials "xxx"
url 'xxx'
}
branches 'refs/head/master'
scriptPath 'Jenkinsfile'
extensions { }
}
}
}
}
configure { project ->
project / 'properties' / 'EnvInjectJobProperty' {
'on'('true')
'info' {
'propertiesContent'('BRANCH=master')
}
}
project / 'properties' / 'org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty' {}
}
}
}
如果使用 JCasC 配置您的 build/pipeline 配置:
要定期构建,无论 SCM 发生什么变化,您可以添加此块:
triggers {
cron('0 6-19 * * *')
}
要定期构建,仅当 有 SCM 更改时,您可以使用此块:
triggers {
scm('0 6-19 * * *')
}
要在上下文中查看此答案,这里有一个代码片段示例:
jobs:
- script: |
job('PROJ-unit-tests') {
scm {
git(gitUrl)
}
triggers {
cron('0 6-19 * * *')
}
steps {
maven('-e clean test')
}
}
摘录并调整自:https://github.com/jenkinsci/configuration-as-code-plugin/issues/876
我正在尝试使用配置即代码 (JCasC) 插件来创建一个定期构建的管道作业,但我无法在网上的任何地方找到它的语法。我正在用 YAML 编写配置。
"Build Periodically" 字段位于管道作业中的“生成触发器”下,并且有一个名为“计划”的文本字段。我的日程安排是 0 6-19 * * *
这甚至可以做到吗?
这是我要编辑的 yaml 文件:
jobs:
- script: >
folder('test1'){
pipelineJob('test1/seedJobTest') {
description 'seedJobTest'
logRotator {
daysToKeep 10
}
definition {
cpsScm {
scm {
git {
remote {
credentials "xxx"
url 'xxx'
}
branches 'refs/head/master'
scriptPath 'Jenkinsfile'
extensions { }
}
}
}
}
configure { project ->
project / 'properties' / 'EnvInjectJobProperty' {
'on'('true')
'info' {
'propertiesContent'('BRANCH=master')
}
}
project / 'properties' / 'org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty' {}
}
}
}
如果使用 JCasC 配置您的 build/pipeline 配置:
要定期构建,无论 SCM 发生什么变化,您可以添加此块:
triggers {
cron('0 6-19 * * *')
}
要定期构建,仅当 有 SCM 更改时,您可以使用此块:
triggers {
scm('0 6-19 * * *')
}
要在上下文中查看此答案,这里有一个代码片段示例:
jobs:
- script: |
job('PROJ-unit-tests') {
scm {
git(gitUrl)
}
triggers {
cron('0 6-19 * * *')
}
steps {
maven('-e clean test')
}
}
摘录并调整自:https://github.com/jenkinsci/configuration-as-code-plugin/issues/876