Triggers

Triggers define what causes a jenkins job to start buliding.

Component: triggers
Macro:trigger
Entry Point:jenkins_jobs.triggers

Example:

job:
  name: test_job

  triggers:
    - timed: '@daily'
build-result

Configure jobB to monitor jobA build result. A build is scheduled if there is a new build result matches your criteria (unstable, failure, ...) Requires the Jenkins BuildResultTrigger Plugin.

Parameters:
  • groups (list) – List groups of jobs and results to monitor for
  • jobs (list) – The jobs to monitor (required)
  • results (list) – Build results to monitor for (default success)
  • combine (bool) – Combine all job information. A build will be scheduled only if all conditions are met (default false)
  • cron (str) – The cron syntax with which to poll the jobs for the supplied result (default ‘’)

Example:

triggers:
  - build-result:
      combine: true
      cron: '* * * * *'
      groups:
        - jobs:
            - foo
            - example
          results:
            - unstable
        - jobs:
            - foo2
          results:
            - not-built
            - aborted
gerrit

Trigger on a Gerrit event. Requires the Jenkins Gerrit Trigger Plugin version >= 2.6.0.

Parameters:
  • trigger-on-patchset-uploaded-event (bool) – Trigger on patchset upload
  • trigger-on-change-abandoned-event (bool) – Trigger on change abandoned. Requires Gerrit Trigger Plugin version >= 2.8.0
  • trigger-on-change-merged-event (bool) – Trigger on change merged
  • trigger-on-change-restored-event (bool) – Trigger on change restored. Requires Gerrit Trigger Plugin version >= 2.8.0
  • trigger-on-comment-added-event (bool) – Trigger on comment added
  • trigger-on-draft-published-event (bool) – Trigger on draft published event
  • trigger-on-ref-updated-event (bool) – Trigger on ref-updated
  • trigger-approval-category (str) – Approval category for comment added
  • trigger-approval-value (int) – Approval value for comment added
  • override-votes (bool) – Override default vote values
  • gerrit-build-successful-verified-value (int) – Successful ‘’Verified’’ value
  • gerrit-build-failed-verified-value (int) – Failed ‘’Verified’’ value
  • gerrit-build-successful-codereview-value (int) – Successful ‘’CodeReview’’ value
  • gerrit-build-failed-codereview-value (int) – Failed ‘’CodeReview’’ value
  • failure-message (str) – Message to leave on failure (default ‘’)
  • successful-message (str) – Message to leave on success (default ‘’)
  • unstable-message (str) – Message to leave when unstable (default ‘’)
  • projects (list) –

    list of projects to match

    Project:
    • project-compare-type (str) – ‘’PLAIN’‘, ‘’ANT’’ or ‘’REG_EXP’‘
    • project-pattern (str) – Project name pattern to match
    • branch-compare-type (str) – ‘’PLAIN’‘, ‘’ANT’’ or ‘’REG_EXP’‘
    • branch-pattern (str) – Branch name pattern to match
    • file-paths (list) – List of file paths to match (optional)
      File Path:
      • compare-type (str) – ‘’PLAIN’‘, ‘’ANT’’ or ‘’REG_EXP’’ (optional, defaults to ‘’PLAIN’‘)
      • pattern (str) – File path pattern to match
  • skip-vote (dict) –

    map of build outcomes for which Jenkins must skip vote. Requires Gerrit Trigger Plugin version >= 2.7.0

    Outcome:
    • successful (bool)
    • failed (bool)
    • unstable (bool)
    • notbuilt (bool)
  • silent (bool) – When silent mode is on there will be no communication back to Gerrit, i.e. no build started/failed/successful approve messages etc. If other non-silent jobs are triggered by the same Gerrit event as this job, the result of this job’s build will not be counted in the end result of the other jobs. (default false)
  • escape-quotes (bool) – escape quotes in the values of gerrit change parameters (default true)
  • no-name-and-email (bool) – Do not pass compound ‘name and email’ parameters (default false)
  • dynamic-trigger-enabled (bool) – Enable/disable the dynamic trigger (default false)
  • dynamic-trigger-url (str) – if you specify this option, the gerrit trigger configuration will be fetched from there on a regular interval
  • custom-url (str) – Custom URL for a message sent to gerrit. Build details URL will be used if empty. (default ‘’)

You may select one or more gerrit events upon which to trigger. You must also supply at least one project and branch, optionally more. If you select the comment-added trigger, you should also indicate which approval category and value you want to trigger the job.

Until version 0.4.0 of Jenkins Job Builder, camelCase keys were used to configure Gerrit Trigger Plugin, instead of hyphenated-keys. While still supported, camedCase keys are deprecated and should not be used.

Example:

triggers:
  - gerrit:
      trigger-on-comment-added-event: true
      trigger-approval-category: 'APRV'
      trigger-approval-value: 1
      projects:
        - project-compare-type: 'PLAIN'
          project-pattern: 'test-project'
          branch-compare-type: 'ANT'
          branch-pattern: '**'
          file-paths:
              - compare-type: ANT
                pattern: subdirectory/**
      skip-vote:
          successful: true
          failed: true
          unstable: true
          notbuilt: true
      silent: false
      escape-quotes: false
      no-name-and-email: false
      dynamic-trigger-enabled: true
      dynamic-trigger-url: http://myhost/mytrigger
github

Trigger a job when github repository is pushed to Requires the Jenkins GitHub Plugin.

Example:

triggers:
  - github
github-pull-request

Build pull requests in github and report results Requires the Jenkins GitHub Pull Request Builder Plugin.

Parameters:
  • admin-list (list) – the users with admin rights (optional)
  • white-list (list) – users whose pull requests build (optional)
  • org-list (list) – orgs whose users should be white listed (optional)
  • cron (string) – cron syntax of when to run (optional)
  • trigger-phrase (string) – when filled, commenting this phrase in the pull request will trigger a build (optional)
  • only-trigger-phrase (bool) – only commenting the trigger phrase in the pull request will trigger a build (default false)
  • github-hooks (bool) – use github hook (default false)
  • permit-all (bool) – build every pull request automatically without asking (default false)
  • auto-close-on-fail (bool) – close failed pull request automatically (default false)

Example:

triggers:
  - github-pull-request:
      admin-list:
        - user1
        - user2
      white-list:
        - user3
        - user4
      org-list:
        - org1
        - org2
      cron: '* * * * *'
      trigger-phrase: 'retest this please'
      only-trigger-phrase: true
      github-hooks: true
      permit-all: false
      auto-close-on-fail: false
pollscm

Poll the SCM to determine if there has been a change.

Parameter:the polling interval (cron syntax)

Example:

triggers:
  - pollscm: "\*/15 * * * \*"
script

Triggers the job using shell or batch script. Requires the Jenkins ScriptTrigger Plugin.

Parameters:
  • label (str) – Restrict where the polling should run. (default ‘’)
  • script (str) – A shell or batch script. (default ‘’)
  • cron (str) – cron syntax of when to run (default ‘’)
  • enable-concurrent (bool) – Enables triggering concurrent builds. (default false)
  • exit-code (int) – If the exit code of the script execution returns this expected exit code, a build is scheduled. (default 0)

Example:

triggers:
  - script:
        script: 'exit 0'
        cron: 'H/15 * * * *'
        enable-concurrent: False
        label: master
        exit-code: 0
timed

Trigger builds at certain times.

Parameter:when to run the job (cron syntax)

Example:

triggers:
  - timed: "@midnight"

Previous topic

SCM

Next topic

Wrappers

This Page