jenkins - 为 Jenkins 配置作为代码插件 (JCasC) 定期构建语法
问题描述
我正在尝试使用配置即代码 (JCasC) 插件来创建一个定期构建的管道作业,但我在网上的任何地方都找不到此语法。我正在用 YAML 编写配置。
“定期构建”字段位于管道作业中的“构建触发器”下,并有一个名为“计划”的文本字段。我的日程是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 来配置您的构建/管道配置:
要定期构建,无论 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
推荐阅读
- go - 在 Golang 切片中偏移零索引
- firebase - 在没有 onSnapshot React-Native 的情况下从 firebase 中提取图像
- node.js - 如何使用 Node.JS 从 JSON 对象中检索特定字段?
- import - 参考上一个单元格中的 Python 代码 [Jupyter Notebook]
- node.js - 如何动态启动 json-server
- java - Java 类、JTable、JInternalFrame、JFrame
- liquid - ruby's any equivalent in liquid?
- leaflet - 传单 api 中的蓝色标记当前位置
- html - VSCode HTML 如何启用自动关闭标签和标签建议
- machine-learning - 我的模型总是给出相同的预测值