This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def commitHashForBuild(build) { | |
def scmAction = build?.actions.find { action -> action instanceof jenkins.scm.api.SCMRevisionAction } | |
if (scmAction?.revision instanceof org.jenkinsci.plugins.github_branch_source.PullRequestSCMRevision) { | |
return scmAction?.revision?.pullHash | |
} else if (scmAction?.revision instanceof jenkins.plugins.git.AbstractGitSCMSource$SCMRevisionImpl) { | |
return scmAction?.revision?.hash | |
} else { | |
error("Build doesn't contain revision information. Do you run this from GitHub organization folder?") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cancelBuilds(int builds_to_scan=300) { | |
def jobName = env.JOB_NAME | |
def currentMR = env.gitlabMergeRequestIid?.toInteger() | |
def currentRepoUrl = env.gitlabSourceRepoURL | |
def currentBuildNumber = env.BUILD_NUMBER?.toInteger() | |
def currentJob = Jenkins.instance.getItemByFullName(jobName) | |
def i = 0 | |
for (def build : currentJob.builds) { | |
if (i > builds_to_scan) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jenkins.model.Jenkins | |
import io.prometheus.client.Collector; | |
import io.prometheus.client.GaugeMetricFamily | |
import io.prometheus.client.CollectorRegistry; | |
import io.prometheus.client.Collector.MetricFamilySamples; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
class BuildsCountByJobCollector extends Collector { | |
private static final Logger LOG = LoggerFactory.getLogger(BuildsCountByJobCollector.class) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jenkins.* | |
import jenkins.model.* | |
import hudson.* | |
import hudson.model.* | |
def credId = 'my_credentials_id' | |
def jenkinsCredentials = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( | |
com.cloudbees.plugins.credentials.Credentials.class, | |
Jenkins.instance, | |
null, |