Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger hourly build from scripted Jenkinsfile

Tags:

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.

Declarative Syntax Example

pipeline {     agent any      triggers {         cron '@daily'     }     ... } 
like image 451
Alex Avatar asked May 22 '17 13:05

Alex


People also ask

Can Jenkins build be triggered automatically?

Follow the steps as mentioned below to trigger a Jenkins job automatically based on GitHub's webhook configurations: Step 1: Go to the Configuration page of the respective job and under the build trigger section, check the "GitHub hook trigger for GITScm polling" checkbox and click on the Save button.

What is the meaning of * * * * * In the schedule text box of the build trigger section?

In the case of 3rd, 4th and 5th parameters asterisks '*' are used which means that no specific day , month and weekday is defined so it would trigger every day for whole month.

Is Jenkinsfile declarative or scripted?

A Jenkinsfile can be written using two types of syntax - Declarative and Scripted. Declarative and Scripted Pipelines are constructed fundamentally differently. Declarative Pipeline is a more recent feature of Jenkins Pipeline which: provides richer syntactical features over Scripted Pipeline syntax, and.


1 Answers

You could use this snippet for Scripted pipeline syntax:

properties(     [         ...  , // other properties that you have         pipelineTriggers([cron('0 * * * *')]),     ] ) 

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.

like image 53
Vadim Kotov Avatar answered Sep 24 '22 13:09

Vadim Kotov