2018-08-21 15:45:59 +02:00
|
|
|
package com.sap.piper
|
|
|
|
|
|
|
|
import com.cloudbees.groovy.cps.NonCPS
|
|
|
|
import jenkins.model.Jenkins
|
2018-10-18 08:51:48 +02:00
|
|
|
import org.jenkinsci.plugins.workflow.steps.MissingContextVariableException
|
2018-08-21 15:45:59 +02:00
|
|
|
|
|
|
|
@NonCPS
|
|
|
|
static def isPluginActive(pluginId) {
|
|
|
|
return Jenkins.instance.pluginManager.plugins.find { p -> p.isActive() && p.getShortName() == pluginId }
|
|
|
|
}
|
2018-10-18 08:51:48 +02:00
|
|
|
|
|
|
|
def nodeAvailable() {
|
|
|
|
try {
|
|
|
|
sh "echo 'Node is available!'"
|
|
|
|
} catch (MissingContextVariableException e) {
|
|
|
|
echo "No node context available."
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2019-01-18 09:25:22 +02:00
|
|
|
|
|
|
|
@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
|
|
|
|
}
|