Skip to content

Commit

Permalink
add smart cleanup in yaxunit
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed Sep 2, 2024
1 parent 938026e commit 71f4791
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/ru/pulsar/jenkins/library/steps/CoverageCleanup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
25 changes: 24 additions & 1 deletion src/ru/pulsar/jenkins/library/steps/Yaxunit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"
}
Expand All @@ -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(" ")

}

// Выполняем команды
Expand Down Expand Up @@ -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}
}
}
8 changes: 6 additions & 2 deletions vars/pipeline1C.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 71f4791

Please sign in to comment.