问题描述
有没有办法使用 Jenkinsfile 脚本化管道 语法触发 Jenkins 作业每小时运行一次?
Is there a way to trigger a Jenkins job to run every hour using the Jenkinsfile scripted pipeline syntax?
我见过使用声明式语法的例子,但没有看到使用管道语法的例子.
I have seen examples using the declarative syntax, but none using the pipeline syntax.
声明式语法示例
pipeline {
agent any
triggers {
cron '@daily'
}
...
}
推荐答案
您可以将此代码段用于脚本化管道语法
:
You could use this snippet for Scripted pipeline syntax
:
properties(
[
... , // other properties that you have
pipelineTriggers([cron('0 * * * *')]),
]
)
属性参考在这里一>.您可以搜索pipelineTriggers"字符串并找出构建触发器可以是例如 artifactory 或此列表中的其他内容(从链接的文档页面中提取 2019-03-23):
Reference for properties is here. You can search for "pipelineTriggers" string and find out that triggers for build can be for example artifactory or something else from this list (extracted 2019-03-23 from linked doc page):
$class: 'ArtifactoryTrigger'
$class: 'AssemblaBuildTrigger'
bitBucketTrigger
bitbucketPush
$class: 'BuildResultTrigger'
$class: 'CIBuildTrigger'
$class: 'CodingPushTrigger'
$class: 'CronFolderTrigger'
$class: 'DeployDbTrigger'
$class: 'DockerHubTrigger'
$class: 'DosTrigger'
$class: 'ElOyente'
$class: 'FanInReverseBuildTrigger'
$class: 'FeatureBranchAwareTrigger'
$class: 'FilesFoundTrigger'
$class: 'FogbugzStatePoller'
$class: 'FolderContentTrigger'
GenericTrigger
gerrit
$class: 'GhprbTrigger'
$class: 'GitBucketPushTrigger'
githubBranches
githubPullRequests
githubPush
gitee
$class: 'GogsTrigger'
issueCommentTrigger
$class: 'IvyTrigger'
$class: 'JiraChangelogTrigger'
$class: 'JiraCommentTrigger'
$class: 'KanboardQueryTrigger'
$class: 'MailCommandTrigger'
$class: 'MavenDependencyUpdateTrigger'
$class: 'NugetTrigger'
p4Trigger
$class: 'PeriodicFolderTrigger'
$class: 'PollMailboxTrigger'
$class: 'PullRequestBuildTrigger'
$class: 'QuayIoTrigger'
$class: 'RemoteBuildTrigger'
upstream
$class: 'RundeckTrigger'
<code>scm</code>
$class: 'SelfieTrigger'
$class: 'SpoonTrigger'
$class: 'SqsBuildTrigger'
$class: 'TeamPRPushTrigger'
$class: 'TeamPushTrigger'
cron
$class: 'URLTrigger'
snapshotDependencies
$class: 'io.relution.jenkins.awssqs.SQSTrigger'
$class: 'io.relution.jenkins.scmsqs.SQSTrigger'
$class: 'org.cloudbees.literate.jenkins.promotions.PromotionTrigger'
$class: 'org.jenkinsci.plugins.deploy.weblogic.trigger.DeploymentTrigger'
$class: 'org.jenkinsci.plugins.deployment.DeploymentTrigger'
有关脚本方式的更多信息此处(来自另一个问题的示例).涵盖声明式管道的文档位于此处.
More info about scripted way here (sample from another question).Documentation that covers declarative pipeline is here.
这篇关于从脚本化的 Jenkinsfile 触发每小时构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!