book
  • README
  • cheatsheet
    • bash
      • builtin
      • syntactic sugar
      • cmd
      • havefun
    • text-processing
      • awk
      • sed
      • html
      • json
      • regex
      • unicode
    • osx
    • curl
    • tricky
    • widget
    • proxy
    • colors
    • math
    • media
    • ssl
      • keystore
      • verification
      • server
      • client
      • tricky
    • windows
      • powershell
      • choco
      • wsl
      • wt
      • shortcut
      • clsid
      • env
      • shell:folder
  • vim
    • nvim
    • install
    • color
    • plugins
      • usage
      • other plugins
      • deprecated
    • tricky
    • viml
    • windows
    • troubleshooting
  • devops
    • admin tools
    • ssh
    • git
      • config
      • alias
      • submodule
      • eol
      • example
      • gerrit
        • gerrit API
      • github
      • troubleshooting
      • tricky
      • statistics
    • pre-commit
    • release-tools
    • tmux
      • cheatsheet
    • ansible
    • vault
    • artifactory
      • api
      • cli
      • aql
      • nginx cert
    • klocwork
      • kwadmin
      • kwserver
      • api
      • q&a
    • elk
    • mongodb
    • android
    • mobile
  • jenkins
    • config
      • windows
    • appearance
    • troubleshooting
    • jenkinsfile
      • utility
      • parallel
      • build
      • envvar
      • properties
      • trigger
      • node
    • script
      • job
      • build
      • stage
      • agent
      • security & authorization
      • exception
      • monitor
      • tricky
    • api
      • blueocean
    • cli
    • plugins
      • kubernetes
      • docker
      • shared-libs
      • lockable-resource
      • ansicolor
      • badge
      • groovy-postbuild
      • simple-theme
      • customizable-header
      • artifactory
      • jira-steps
      • job-dsl
      • build-timeline
      • crumbIssuer
      • coverage
      • uno-choice
      • tricky
  • virtualization
    • kubernetes
      • init
        • kubespray
        • kubeadm
          • environment
          • crio v1.30.4
          • docker v1.15.3
          • HA
        • addons
        • etcd
      • kubectl
        • pod
        • deploy
        • replicasets
        • namespace
        • secrets
      • node
      • certificates
      • events
      • kubeconfig
      • kubelet
      • troubleshooting
      • cheatsheet
      • auth
      • api
      • tools
        • monitor
        • helm
        • network
        • minikube
    • docker
      • run & exec
      • voume
      • remove
      • show info
      • dockerfile
      • dockerd
      • tricky
      • troubleshooting
      • windows
    • crio
    • podman
  • ai
    • prompt
  • osx
    • apps
      • init
      • brew
    • defaults
    • system
    • network
    • script
    • tricky
  • linux
    • devenv
    • util
      • time & date
      • output formatting
      • params
      • tricky
    • nutshell
    • disk
    • network
    • troubleshooting
    • system
      • apt/yum/snap
      • authorization
      • apps
      • x11
    • ubuntu
      • systemctl
      • x
    • rpi
  • programming
    • groovy
    • python
      • config
      • basic
      • list
      • pip
      • q&a
    • others
    • archive
      • angular
      • maven
      • mysql
        • installation
        • logs
      • ruby
        • rubyInstallationQ&A
  • tools
    • fonts
    • html & css
    • Jira & Confluence
    • node & npm
      • gitbook
      • hexo
      • github.page
      • code themes
    • app
      • microsoft office
      • vscode
      • virtualbox
      • iterm2
      • browser
      • skype
      • teamviewer
      • others
  • quotes
  • english
Powered by GitBook
On this page
  • trigger
  • triggered by

Was this helpful?

  1. jenkins
  2. jenkinsfile

trigger

PreviouspropertiesNextnode

Last updated 1 year ago

Was this helpful?

trigger

poll SCM

properties([
  // every 6 hours
  pipelineTriggers([
    pollSCM( ignorePostCommitHooks: true, scmpoll_spec: 'H H/6 * * *' )
  ])
])
properties([
  pipelineTriggers([
    [ $class: "SCMTrigger", scmpoll_spec: 'H/5 * * * *' ],
  ])
])
  • declarative:

    triggers {
      pollSCM ignorePostCommitHooks: true, scmpoll_spec: 'H H * * *'
    }
properties([
  parameters([
    choice(choices: ['', 'a', 'b', 'c'], description: '', name: 'var1')
    choice(choices: ['', 'a', 'b', 'c'], description: '', name: 'var2')
  ]),
  pipelineTriggers([
    parameterizedCron( '''
      H/3 * * * * % var1=a; var2=b
      H/6 * * * * % var1=b; var2=a
    ''' )
  ])
])

triggered by

references:

  • get build cause

    import hudson.model.Cause.UserIdCause
    import org.jenkinsci.plugins.workflow.job.WorkflowRun
    
    workflowRun build = currentBuild.rawBuild
    
    println build.getCauses().collect { it.getClass().getCanonicalName() }
    println build.getCauses().collect { it.getClass().getCanonicalName() }.collect { it.tokenize('.').last() }
    
    println """
      cause                               : ${build.getCauses().toString()}
      cause.getClass()                    : ${build.getCauses().getClass()} : ${build.getCauses().getClass().getCanonicalName()}
      build.getCause( UserIdCause.class ) : ${build.getCause( UserIdCause.class )}
    """
    • console output

      [Pipeline] echo
      [hudson.model.Cause.UserIdCause]
      [Pipeline] echo
      [UserIdCause]
      [Pipeline] echo
      
          cause                               : [hudson.model.Cause$UserIdCause@bf8cb337]
          cause.getClass()                    : class java.util.Collections$UnmodifiableRandomAccessList : java.util.Collections.UnmodifiableRandomAccessList
          build.getCause( UserIdCause.class ) : hudson.model.Cause$UserIdCause@bf8cb337
  • get user id if triggered by manually

    import hudson.model.Cause.UserIdCause
    import org.jenkinsci.plugins.workflow.job.WorkflowRun
    
    workflowRun build = currentBuild.rawBuild
    if ( build.getCause(UserIdCause.class) ) {
      println """
        username : ${build.getCause(hudson.model.Cause.UserIdCause.class).getUserName()}
        id       : ${build.getCause(hudson.model.Cause.UserIdCause.class).getUserId()}
        mail     : ${build.getCause(hudson.model.Cause.UserIdCause.class).getUserId()}@domain.com
      """
    }
    • or

      import hudson.model.Cause.UserIdCause
      
      if ( build.getCause(UserIdCause.class) ) {
        println """
          username : ${build.getCause(UserIdCause.class).getUserName()}
          id       : ${build.getCause(UserIdCause.class).getUserId()}
          mail     : ${build.getCause(UserIdCause.class).getUserId()}@domain.com
        """
      }
  • get causedby

    import org.jenkinsci.plugins.workflow.job.WorkflowRun
    import hudson.model.Cause.*
    import hudson.triggers.TimerTrigger.TimerTriggerCause
    import org.jenkinsci.plugins.workflow.cps.replay.ReplayCause
    import org.jenkinsci.plugins.parameterizedscheduler.ParameterizedTimerTriggerCause
    import org.jenkinsci.plugins.workflow.cps.replay.ReplayCause
    import com.sonyericsson.rebuild.RebuildCause
    
    def getCasuedBy( workflowRun build = currentBuild.rawBuild ) {
        CauseAction causeAction = currentBuild.rawBuild.getAction(CauseAction.class)
        causeAction.getCauses().each { Cause cause ->
          if ( cause instanceof Cause.UpstreamCause            ) println ( 'by upstream'                  )
          if ( cause instanceof Cause.UserIdCause              ) println ( 'by user'                      )
          if ( cause instanceof ReplayCause                    ) println ( 'by reply'                     )
          if ( cause instanceof RebuildCause                   ) println ( 'by rebuild'                   )
          if ( cause instanceof TimerTriggerCause              ) println ( 'by timer'                     )
          if ( cause instanceof ParameterizedTimerTriggerCause ) println ( 'by ParameterizedTimerTrigger' )
        }
    }
  • gitlab

    currentBuild.rawBuild.getCause(com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause).getData()
    // or
    commit = currentBuild.rawBuild.getCause(com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause).getData().getLastCommit()

libs

import hudson.model.Cause.*
import hudson.triggers.TimerTrigger.TimerTriggerCause
import org.jenkinsci.plugins.parameterizedscheduler.ParameterizedTimerTriggerCause
import org.jenkinsci.plugins.workflow.cps.replay.ReplayCause
import com.sonyericsson.rebuild.RebuildCause

Boolean byCron( WorkflowRun build = currentBuild.rawBuild ) {
  build.getCause( TimerTriggerCause.class ) && true
}
Boolean byParameterizedCron( WorkflowRun build = currentBuild.rawBuild ) {
  build.getCause( ParameterizedTimerTriggerCause.class ) && true
}
Boolean byTimer( WorkflowRun build = currentBuild.rawBuild ) {
  byCron( build ) || byParameterizedCron( build )
}
Boolean byUpstream( WorkflowRun build = currentBuild.rawBuild ) {
  build.getCause( Cause.UpstreamCause.class ) && true
}
Boolean byUserId( WorkflowRun build = currentBuild.rawBuild ) {
  build.getCause( Cause.UserIdCause.class ) && true
}
Boolean byReplay( WorkflowRun build = currentBuild.rawBuild ) {
  byUserId( build ) && build.getCause( ReplayCause.class )
}
Boolean byRebuild( WorkflowRun build = currentBuild.rawBuild ) {
  byUserId( build ) && build.getCause( RebuildCause.class )
}

GerritCause

check

parameterizedCron
gitlab
CauseAction.class
Cause.UpstreamCause
Cause.UserIdCause
RebuildCause
ReplayCause
TimerTrigger.TimerTriggerCause
ParameterizedTimerTriggerCause
source code : yet-another-build-visualizer-plugin
imarslo : GerritCause
trigger
poll SCM
parameterizedCron
triggered by
libs
GerritCause