Skip to content

Commit

Permalink
add logging to start step
Browse files Browse the repository at this point in the history
  • Loading branch information
ovcharenko-di committed Dec 13, 2024
1 parent d8cd62f commit 0a78703
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/ru/pulsar/jenkins/library/steps/Start.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,31 @@ class Start implements Serializable {

void run() {
IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()
def env = steps.env()

def executable_name = getExecutableName(executable)
if (steps.isUnix()) {
steps.sh("$executable $params &", false, false , encoding)
steps.sh("$executable $params > \"./build/${env.STAGE_NAME}-start-${executable_name}.log 2>&1 &", false, false , encoding)
} else {
steps.bat("chcp 65001 > nul \nstart \"\" /B \"$executable\" $params", false, false, encoding)
steps.bat("chcp 65001 > nul \nstart \"\" /B \"$executable\" $params > \"./build/${env.STAGE_NAME}-start-${executable_name}.log\" 2>&1", false, false, encoding)
}
}

static String getExecutableName(String executable) {

IStepExecutor steps = ContextRegistry.getContext().getStepExecutor()

String normalizedPath = executable.replace("\\", "/")
String executableName = normalizedPath.substring(normalizedPath.lastIndexOf("/") + 1)

// Remove the file extension if it exists on Windows systems (e.g., .exe, .cmd, .bat)
if (!steps.isUnix()) {
int extensionIndex = executableName.lastIndexOf(".")
if (extensionIndex != -1) {
executableName = executableName.substring(0, extensionIndex)
}
}

return executableName
}
}

0 comments on commit 0a78703

Please sign in to comment.