From fcebf6f6645dd488fe6a188ee9150315f05c1fb0 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 4 Mar 2025 09:47:04 +0100 Subject: [PATCH] ci: refs #8698 move functions inside script step --- Jenkinsfile | 146 ++++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 28a77f4d3..a904d2fd3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,80 @@ def BRANCH_ENV = [ beta: 'production' ] +def getSpec(path) { + return "test/cypress/integration/" + path.split("/")[2] + "/**/*.spec.js" +} +def getSpecs() { + return script { + def searchFiles = { searchString -> + def pagesPath = "src/pages" + + def matchingFiles = sh( + script: "grep -rl '${searchString}' ${pagesPath} || true", + returnStdout: true + ).trim().split("\n") + + matchingFiles = matchingFiles.findAll { it.trim() } + def extractedFolders = matchingFiles.collect { getSpec(it) }.unique() + extractedFolders.add(getSpec(searchString)) + + echo "Carpetas donde se encontró '${searchString}': ${extractedFolders}" + return extractedFolders + } + + def lastCommit + def lastSuccessfulBuild = currentBuild.previousBuild + def currentCommit = sh( + script: "git rev-parse HEAD", + returnStdout: true + ).trim() + def files = [] + + while (lastSuccessfulBuild != null && lastSuccessfulBuild.result != 'SUCCESS') { + lastSuccessfulBuild = lastSuccessfulBuild.previousBuild + } + if (lastSuccessfulBuild != null && lastSuccessfulBuild.changeSets.size() > 0) { + for (changeSet in lastSuccessfulBuild.changeSets) { + for (change in changeSet.items) { + lastCommit = change.commitId + break + } + } + + if (lastCommit) { + echo "Último commit exitoso: ${lastCommit}" + } + } + + if(!lastCommit) { + lastCommit = sh(script: "git rev-parse origin/${env.CHANGE_TARGET}}", returnStdout: true).trim() + echo "Hash obtenido con git: ${lastCommit}" + } + + + def modifiedFiles = sh( + script: "git diff --name-only ${lastCommit} ${currentCommit}", + returnStdout: true + ).trim().split("\n") + + modifiedFiles.each { file -> + echo "- ${file}" + if(!file.startsWith('src/pages')){ + if(file.startsWith('test/cypress/integration')){ + files.add(file) + } + //else { + // files = 'test/cypress/integration/**/*.spec.js' + // return + // } + } else{ + files = (files + searchFiles(file)).unique() + } + } + return files + } +} @@ -122,79 +195,6 @@ pipeline { def image = docker.build('lilium-dev', '-f docs/Dockerfile.dev docs') sh "docker-compose ${env.COMPOSE_PARAMS} up -d" - def searchFiles = { searchString -> - def pagesPath = "src/pages" - - def matchingFiles = sh( - script: "grep -rl '${searchString}' ${pagesPath} || true", - returnStdout: true - ).trim().split("\n") - - matchingFiles = matchingFiles.findAll { it.trim() } - def extractedFolders = matchingFiles.collect { getSpec(it) }.unique() - extractedFolders.add(getSpec(searchString)) - - echo "Carpetas donde se encontró '${searchString}': ${extractedFolders}" - return extractedFolders - } - - def getSpec(path) { - return "test/cypress/integration/" + path.split("/")[2] + "/**/*.spec.js" - } - - def getSpecs() { - def lastCommit - def lastSuccessfulBuild = currentBuild.previousBuild - def currentCommit = sh( - script: "git rev-parse HEAD", - returnStdout: true - ).trim() - def files = [] - - while (lastSuccessfulBuild != null && lastSuccessfulBuild.result != 'SUCCESS') { - lastSuccessfulBuild = lastSuccessfulBuild.previousBuild - } - if (lastSuccessfulBuild != null && lastSuccessfulBuild.changeSets.size() > 0) { - for (changeSet in lastSuccessfulBuild.changeSets) { - for (change in changeSet.items) { - lastCommit = change.commitId - break - } - } - - if (lastCommit) { - echo "Último commit exitoso: ${lastCommit}" - } - } - - if(!lastCommit) { - lastCommit = sh(script: "git rev-parse origin/${env.CHANGE_TARGET}}", returnStdout: true).trim() - echo "Hash obtenido con git: ${lastCommit}" - } - - - def modifiedFiles = sh( - script: "git diff --name-only ${lastCommit} ${currentCommit}", - returnStdout: true - ).trim().split("\n") - - modifiedFiles.each { file -> - echo "- ${file}" - if(!file.startsWith('src/pages')){ - if(file.startsWith('test/cypress/integration')){ - files.add(file) - } - //else { - // files = 'test/cypress/integration/**/*.spec.js' - // return - // } - } else{ - files = (files + searchFiles(file)).unique() - } - } - return files - } - def specs = getSpecs() image.inside("--network ${env.COMPOSE_PROJECT}_default -e CI -e TZ") { sh "cypress run --browser chromium --spec ${specs} || true"