DO-90/fixed_ssh_connect (#6)

*Update git class
* Add jenkins class
This commit is contained in:
Aleksandr Vodyanov
2023-10-05 09:34:12 +00:00
parent 613d06db4e
commit 12bca2e713
2 changed files with 128 additions and 4 deletions

View File

@@ -0,0 +1,34 @@
package com.ncloudtech.jenkins
import hudson.model.Result
import jenkins.model.CauseOfInterruption
import jenkins.model.Jenkins
/**
* Class is for working with Jenkins
*/
class Jenkins implements Serializable {
// See https://www.baeldung.com/java-serial-version-uid
private static final long serialVersionUID = 1L
/**
* Method cancel previous builds
* @param jobName String - name of currentJob
* @param buildNumber int - build number of current job
* @param currentBuild current build information
*/
static void cancelPreviousBuilds(String jobName, int buildNumber, def currentBuild) {
def currentJob = jenkins.model.Jenkins.instance.getItemByFullName(jobName)
for (def build : currentJob.builds) {
def exec = build.getExecutor()
if (build.isBuilding() && build.number.toInteger() < buildNumber && exec != null) {
exec.interrupt(
Result.ABORTED,
new CauseOfInterruption.UserInterruption("Job aborted by #${currentBuild.number}")
)
}
}
}
}