1
0
mirror of https://github.com/firstBitMarksistskaya/jenkins-lib.git synced 2025-08-25 20:09:25 +02:00

switch pids from env to the file

This commit is contained in:
Dima
2024-09-03 10:29:27 +03:00
parent c147ebb924
commit 14268a1a29
4 changed files with 27 additions and 19 deletions

View File

@@ -8,11 +8,13 @@ import ru.pulsar.jenkins.library.utils.Logger
class CoverageCleanup implements Serializable {
private final JobConfiguration config
private final String stageName
private String encoding = 'UTF-8'
CoverageCleanup(JobConfiguration config) {
CoverageCleanup(JobConfiguration config, String stageName = "") {
this.config = config
this.stageName = stageName
}
def run() {
@@ -20,21 +22,28 @@ class CoverageCleanup implements Serializable {
Logger.printLocation()
def env = steps.env();
String dbgsPIDS = env.YAXUNIT_DBGS_PIDS // space-delimited string
String coverage41CPIDS = env.YAXUNIT_COVERAGE41C_PIDS // space-delimited string
String pidsFilePath = ""
if (stageName == 'yaxunit') {
pidsFilePath = Yaxunit.COVERAGE_PIDS_PATH
}
def combined = (dbgsPIDS + " " + coverage41CPIDS).trim()
def pids = ""
if (steps.fileExists(pidsFilePath)) {
pids = steps.readFile(pidsFilePath)
}
if (combined.isEmpty()) {
if (pids.isEmpty()) {
Logger.println("Нет запущенных процессов dbgs и Coverage41C")
return
}
Logger.println("Завершение процессов dbgs и Coverage41C с pid: $pids")
if (steps.isUnix()) {
def command = "kill $combined"
def command = "kill $pids"
steps.sh(command, true, false, encoding)
} else {
def winCommand = combined.split(" ")
def winCommand = pids.split(" ")
.each { it -> "/PID $it" }
.join(" ")
def command = "taskkill $winCommand /F"

View File

@@ -19,6 +19,7 @@ class Yaxunit implements Serializable {
public static final String YAXUNIT_ALLURE_STASH = 'yaxunit-allure'
public static final String COVERAGE_STASH_NAME = 'yaxunit-coverage'
public static final String COVERAGE_STASH_PATH = 'build/out/yaxunit-coverage.xml'
public static final String COVERAGE_PIDS_PATH = 'build/yaxunit-pids'
Yaxunit(JobConfiguration config) {
this.config = config
@@ -89,10 +90,12 @@ class Yaxunit implements Serializable {
newDbgsPids.removeAll(currentDbgsPids)
newCoverage41CPids.removeAll(currentCoverage41CPids)
env.YAXUNIT_DBGS_PIDS = newDbgsPids.join(" ")
steps.echo("YAXUNIT_DBGS_PIDS = $env.YAXUNIT_DBGS_PIDS")
env.YAXUNIT_COVERAGE41C_PIDS = newCoverage41CPids.join(" ")
steps.echo("YAXUNIT_COVERAGE41C_PIDS = $env.YAXUNIT_COVERAGE41C_PIDS")
newDbgsPids.addAll(newCoverage41CPids)
def pids = newDbgsPids.join(" ")
steps.writeFile(COVERAGE_PIDS_PATH, pids, 'UTF-8')
Logger.println("Coverage PIDs for cleanup: $pids")
}

View File

@@ -2,10 +2,10 @@ import ru.pulsar.jenkins.library.configuration.JobConfiguration
import ru.pulsar.jenkins.library.ioc.ContextRegistry
import ru.pulsar.jenkins.library.steps.CoverageCleanup
def call(JobConfiguration config) {
def call(JobConfiguration config, String stageName) {
ContextRegistry.registerDefaultContext(this)
def coverageCleanup = new CoverageCleanup(config);
def coverageCleanup = new CoverageCleanup(config, stageName)
coverageCleanup.run()
}

View File

@@ -320,10 +320,6 @@ void call() {
}
stage('Выполнение YAXUnit тестов') {
environment {
YAXUNIT_DBGS_PIDS = ""
YAXUNIT_COVERAGE41C_PIDS = ""
}
steps {
timeout(time: config.timeoutOptions.yaxunit, unit: TimeUnit.MINUTES) {
yaxunit config
@@ -331,7 +327,7 @@ void call() {
}
post {
cleanup {
coverageCleanup config
coverageCleanup config, 'yaxunit'
}
}
}