package com.sap.piper import com.cloudbees.groovy.cps.NonCPS import jenkins.model.Jenkins import org.jenkinsci.plugins.workflow.steps.MissingContextVariableException @NonCPS static def isPluginActive(pluginId) { return Jenkins.instance.pluginManager.plugins.find { p -> p.isActive() && p.getShortName() == pluginId } } def nodeAvailable() { try { sh "echo 'Node is available!'" } catch (MissingContextVariableException e) { echo "No node context available." return false } return true } @NonCPS def getCurrentBuildInstance() { return currentBuild } @NonCPS def getRawBuild() { return getCurrentBuildInstance().rawBuild } def isJobStartedByTimer() { return isJobStartedByCause(hudson.triggers.TimerTrigger.TimerTriggerCause.class) } def isJobStartedByUser() { return isJobStartedByCause(hudson.model.Cause.UserIdCause.class) } @NonCPS def isJobStartedByCause(Class cause) { def startedByGivenCause = false def detectedCause = getRawBuild().getCause(cause) if (null != detectedCause) { startedByGivenCause = true echo "Found build cause ${detectedCause}" } return startedByGivenCause }