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

add smart cleanup in yaxunit

This commit is contained in:
Dima
2024-09-02 16:06:02 +03:00
parent 5c7a6e0a45
commit a7e4d3b290
3 changed files with 40 additions and 5 deletions

View File

@@ -20,11 +20,19 @@ class CoverageCleanup implements Serializable {
Logger.printLocation()
String dbgsPIDS = env.YAXUNIT_DBGS_PIDS
String coverage41CPIDS = env.YAXUNIT_COVERAGE41C_PIDS
def combined = dbgsPIDS + " " + coverage41CPIDS
if (steps.isUnix()) {
def command = "pkill Coverage41C ; pkill dbgs"
def command = "pkill $combined"
steps.sh(command, true, false, encoding)
} else {
def command = "taskkill /IM Coverage41C /F & taskkill /IM dbgs /F"
def winCommand = combined.split(" ")
.each { it -> "/PID $it" }
.join(" ")
def command = "taskkill $winCommand /F"
steps.sh(command, true, false, encoding)
}
}

View File

@@ -14,7 +14,7 @@ class Yaxunit implements Serializable {
private final JobConfiguration config
private final String DEFAULT_YAXUNIT_CONFIGURATION_RESOURCE = 'yaxunit.json'
private static final String DEFAULT_YAXUNIT_CONFIGURATION_RESOURCE = 'yaxunit.json'
public static final String YAXUNIT_ALLURE_STASH = 'yaxunit-allure'
public static final String COVERAGE_STASH_NAME = 'yaxunit-coverage'
@@ -71,6 +71,8 @@ class Yaxunit implements Serializable {
def coverageOpts = config.coverageOptions
def port = options.dbgsPort
def lockableResource = RandomStringUtils.random(9, true, false)
def currentDbgsPids = getPIDs("dbgs")
def currentCoverage41CPids = getPIDs("Coverage41C")
if (options.coverage) {
lockableResource = "${env.NODE_NAME}_$port"
}
@@ -80,6 +82,13 @@ class Yaxunit implements Serializable {
steps.start("${coverageOpts.dbgsPath} --addr=127.0.0.1 --port=$port")
steps.start("${coverageOpts.coverage41CPath} start -i DefAlias -u http://127.0.0.1:$port -P $workspaceDir -s $srcDir -o $COVERAGE_STASH_PATH")
steps.cmd("${coverageOpts.coverage41CPath} check -i DefAlias -u http://127.0.0.1:$port")
def newDbgsPids = getPIDs("dbgs")
def newCoverage41CPids = getPIDs("Coverage41C")
env.YAXUNIT_DBGS_PIDS = (newDbgsPids - currentDbgsPids).join(" ")
env.YAXUNIT_COVERAGE41C_PIDS = (newCoverage41CPids - currentCoverage41CPids).join(" ")
}
// Выполняем команды
@@ -116,4 +125,18 @@ class Yaxunit implements Serializable {
steps.stash(COVERAGE_STASH_NAME, COVERAGE_STASH_PATH, true)
}
}
private static ArrayList<String> getPIDs(String name) {
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
String pids
if (steps.isUnix()) {
pids = steps.sh("pidof $name", false, true, 'UTF-8')
} else {
pids = steps.bat("chcp 65001 > nul \nfor /f \"tokens=2\" %a in ('tasklist ^| findstr $name') do @echo %a", false, true, 'UTF-8')
}
return pids.split('\n').collect{it as String}
}
}

View File

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