diff --git a/src/eu/indigo/JenkinsDefinitions.groovy b/src/eu/indigo/JenkinsDefinitions.groovy index c0694387..e7bb8f0d 100644 --- a/src/eu/indigo/JenkinsDefinitions.groovy +++ b/src/eu/indigo/JenkinsDefinitions.groovy @@ -23,6 +23,12 @@ class JenkinsDefinitions implements Serializable { */ JenkinsDefinitions(steps) { this.steps = steps + if(_DEBUG_) { + this.logLevel = _LOGLEVELMAX_ + } + else { + this.logLevel = steps.env.JPL_DEBUG ? steps.env.JPL_DEBUG as int : logLevel + } } void setLogLevel(int level) { @@ -30,7 +36,7 @@ class JenkinsDefinitions implements Serializable { logLevel = _LOGLEVELMAX_ } else { - logLevel = steps.env.JPL_DEBUG ? steps.env.JPL_DEBUG : logLevel + logLevel = steps.env.JPL_DEBUG ? steps.env.JPL_DEBUG as int : level } } diff --git a/src/eu/indigo/compose/DockerCompose.groovy b/src/eu/indigo/compose/DockerCompose.groovy index 113f2a52..f4ee2497 100644 --- a/src/eu/indigo/compose/DockerCompose.groovy +++ b/src/eu/indigo/compose/DockerCompose.groovy @@ -35,11 +35,11 @@ class DockerCompose extends JenkinsDefinitions implements Serializable { * @param block The expected logical block to be executed */ def withCredentialsClosure(List credentials, Closure block) { - if (_DEBUG_) { steps.echo "** withCredentialsClosure() **" } + if (logTest(1)) { steps.echo "** withCredentialsClosure() **" } if (credentials) { - if (_DEBUG_) { steps.echo "credentials:\n${credentials}" } + if (logTest(1)) { steps.echo "credentials:\n${credentials}" } List credentialsStatements = credentialsToStep(credentials) - if (_DEBUG_) { steps.echo 'credentialsToStep: ' + credentialsStatements } + if (logTest(1)) { steps.echo 'credentialsToStep: ' + credentialsStatements } steps.withCredentials(credentialsStatements) { block() } @@ -55,12 +55,12 @@ class DockerCompose extends JenkinsDefinitions implements Serializable { */ List credentialsToStep(List credentials) { credentialVariablesNames = [] - if (_DEBUG_) { steps.echo "** credentialsToStep() **" } - if (_DEBUG_) { steps.echo "credentialVariablesNames(start):\n${credentialVariablesNames}" } + if (logTest(1)) { steps.echo "** credentialsToStep() **" } + if (logTest(1)) { steps.echo "credentialVariablesNames(start):\n${credentialVariablesNames}" } credentials.collect { credential -> def credType = credential.type - if (_DEBUG_) { steps.echo "credential: $credential\ncredType: $credType" } + if (logTest(1)) { steps.echo "credential: $credential\ncredType: $credType" } def credValue switch (credType) { case 'string': @@ -102,8 +102,8 @@ class DockerCompose extends JenkinsDefinitions implements Serializable { break } - if (_DEBUG_) { steps.echo "credentialVariablesNames(end):\n${credentialVariablesNames}" } - if (_DEBUG_) { steps.echo "credValue: $credValue" } + if (logTest(1)) { steps.echo "credentialVariablesNames(end):\n${credentialVariablesNames}" } + if (logTest(1)) { steps.echo "credValue: $credValue" } credValue } } @@ -148,8 +148,8 @@ class DockerCompose extends JenkinsDefinitions implements Serializable { String getCredsVars() { String res = '' - if (_DEBUG_) { steps.echo "** getCredsVars() **" } - if (_DEBUG_) { steps.echo "credentialVariablesNames:\n${credentialVariablesNames}" } + if (logTest(1)) { steps.echo "** getCredsVars() **" } + if (logTest(1)) { steps.echo "credentialVariablesNames:\n${credentialVariablesNames}" } if (! credentialVariablesNames?.isEmpty()) { credentialVariablesNames.each { v -> @@ -265,11 +265,11 @@ class DockerCompose extends JenkinsDefinitions implements Serializable { * @see https://docs.docker.com/compose/reference/exec/ */ def composeToxRun(Map args, String service, String testenv, Tox tox) { - if (_DEBUG_) { steps.echo "** composeToxRun() **" } + if (logTest(1)) { steps.echo "** composeToxRun() **" } String credsVars = getCredsVars() - if (_DEBUG_) { steps.echo "service: ${service}\ntestenv: ${testenv}\ntoxFile: " + escapeWhitespace(args.toxFile) + "\ncredsVars: $credsVars" } - if (_DEBUG_) { steps.echo "tox command: " + tox.runEnv(testenv, toxFile: escapeWhitespace(args.toxFile)) } + if (logTest(1)) { steps.echo "service: ${service}\ntestenv: ${testenv}\ntoxFile: " + escapeWhitespace(args.toxFile) + "\ncredsVars: $credsVars" } + if (logTest(1)) { steps.echo "tox command: " + tox.runEnv(testenv, toxFile: escapeWhitespace(args.toxFile)) } String cmd = parseParam(_f, escapeWhitespace(args.composeFile)) + ' ' + parseParam(_w, escapeWhitespace(args.workdir)) + ' exec -T ' + " $credsVars $service " + tox.runEnv(testenv, toxFile: escapeWhitespace(args.toxFile)) steps.sh "docker-compose $cmd" @@ -305,9 +305,9 @@ class DockerCompose extends JenkinsDefinitions implements Serializable { */ def processStages(projectConfig) { String workspace = steps.env.WORKSPACE + '/' - if (_DEBUG_) { steps.echo "** processStages() **" } - if (_DEBUG_) { steps.echo "workspace path: $workspace" } - if (_DEBUG_) { steps.sh 'echo "before loading credentials:\n$(env)"' } + if (logTest(1)) { steps.echo "** processStages() **" } + if (logTest(1)) { steps.echo "workspace path: $workspace" } + if (logTest(1)) { steps.sh 'echo "before loading credentials:\n$(env)"' } // Load debug settings defined in JenkinsDefinitions before starting the scripted pipeline debugSettings() @@ -333,7 +333,7 @@ class DockerCompose extends JenkinsDefinitions implements Serializable { // Deploy the environment services using docker-compose composeUp(composeFile: projectConfig.config.deploy_template, workdir: workspace, forceBuild: steps.env.JPL_DOCKERFORCEBUILD) - if (_DEBUG_) { steps.sh 'echo "after loading credentials:\n$(env)"' } + if (logTest(1)) { steps.sh 'echo "after loading credentials:\n$(env)"' } projectConfig.stagesList.each { stageMap -> if (steps.env.JPL_KEEPGOING) { diff --git a/src/eu/indigo/compose/parser/ConfigParser.groovy b/src/eu/indigo/compose/parser/ConfigParser.groovy index d287383f..c8f61a84 100644 --- a/src/eu/indigo/compose/parser/ConfigParser.groovy +++ b/src/eu/indigo/compose/parser/ConfigParser.groovy @@ -79,7 +79,7 @@ class ConfigParser extends JenkinsDefinitions implements Serializable { ] ProjectConfiguration parse(yaml, env) { - if (_DEBUG_) { steps.echo "** parse(): ${yaml}**" } + if (logTest(1)) { steps.echo "** parse(): ${yaml}**" } new ProjectConfigurationBuilder() .setNodeAgentAux(getNodeAgent(yaml)) @@ -93,7 +93,7 @@ class ConfigParser extends JenkinsDefinitions implements Serializable { } Map merge(Map[] sources) { - if (_DEBUG_) { steps.echo "** merge(): ${sources}**" } + if (logTest(1)) { steps.echo "** merge(): ${sources}**" } switch (sources.length) { case 0: return [:] @@ -103,7 +103,7 @@ class ConfigParser extends JenkinsDefinitions implements Serializable { Map result = [:] (sources[0].entrySet() + sources[1].entrySet()).each { entry -> - if (_DEBUG_) { steps.echo "result = $result\nkey = ${entry.key}\nvalue = ${entry.value}" } + if (logTest(1)) { steps.echo "result = $result\nkey = ${entry.key}\nvalue = ${entry.value}" } result[entry.key] = result.containsKey(entry.key) && result[entry.key].getClass() == Map ? [:] << result[entry.key] << entry.value : entry.value @@ -113,7 +113,7 @@ class ConfigParser extends JenkinsDefinitions implements Serializable { } Map getDefaultValue(String setting) { - if (_DEBUG_) { steps.echo "** getDefaultValue(): ${setting}**" } + if (logTest(1)) { steps.echo "** getDefaultValue(): ${setting}**" } defaultValues[setting].collectEntries { k, v -> v.getClass() == Map ? @@ -123,7 +123,7 @@ class ConfigParser extends JenkinsDefinitions implements Serializable { } def getNodeAgent(yaml) { - if (_DEBUG_) { steps.echo "** getNodeAgent() **" } + if (logTest(1)) { steps.echo "** getNodeAgent() **" } configToClass[(yaml.config?.node_agent == null) ? DEFAULT_AGENT : yaml.config.node_agent] } @@ -147,7 +147,7 @@ class ConfigParser extends JenkinsDefinitions implements Serializable { } Map getConfigSetting(Map config) { - if (_DEBUG_) { steps.echo "** getConfigSetting() **" } + if (logTest(1)) { steps.echo "** getConfigSetting() **" } def configBase = config ? merge(getDefaultValue('config'), config) : merge(getDefaultValue('config')) def configRepos = [ project_repos: configBase['project_repos'] @@ -164,34 +164,34 @@ class ConfigParser extends JenkinsDefinitions implements Serializable { def configBaseRepos = merge(configBase, configRepos) def configMerged = merge(configBaseRepos, configCredentials) - if (_DEBUG_) { steps.echo 'configBase:\n' + configBase.toString() } - if (_DEBUG_) { steps.echo 'configRepos:\n' + configRepos.toString() } - if (_DEBUG_) { steps.echo 'configCredentials:\n' + configCredentials.toString() } - if (_DEBUG_) { steps.echo 'configBaseRepos:\n' + configBaseRepos.toString() } - if (_DEBUG_) { steps.echo 'configMerged:\n' + configMerged.toString() } + if (logTest(1)) { steps.echo 'configBase:\n' + configBase.toString() } + if (logTest(1)) { steps.echo 'configRepos:\n' + configRepos.toString() } + if (logTest(1)) { steps.echo 'configCredentials:\n' + configCredentials.toString() } + if (logTest(1)) { steps.echo 'configBaseRepos:\n' + configBaseRepos.toString() } + if (logTest(1)) { steps.echo 'configMerged:\n' + configMerged.toString() } return configMerged } Map getSQASetting(Map criteria) { - if (_DEBUG_) { steps.echo "** getSQASetting() **" } - if (_DEBUG_) { steps.echo "criteria:\n$criteria" } + if (logTest(1)) { steps.echo "** getSQASetting() **" } + if (logTest(1)) { steps.echo "criteria:\n$criteria" } def sqaCriteria = criteria.each { criterion, data -> supportedBuildTools.each { tool -> - if (_DEBUG_) { steps.echo "tool: $tool" } - if (_DEBUG_) { steps.echo "data:\n$data" } + if (logTest(1)) { steps.echo "tool: $tool" } + if (logTest(1)) { steps.echo "data:\n$data" } def repoData = data[_repos].collectEntries { id, params -> - if (_DEBUG_) { steps.echo "id: $id\nparams:\n$params" } + if (logTest(1)) { steps.echo "id: $id\nparams:\n$params" } params.containsKey(tool) ? [id, merge(getDefaultValue(tool), params)] : [id, params] } data[_repos] = repoData } } - if (_DEBUG_) { steps.echo "sqaCriteria:\n$sqaCriteria" } + if (logTest(1)) { steps.echo "sqaCriteria:\n$sqaCriteria" } return sqaCriteria } List formatStages(Map criteria) { - if (_DEBUG_) { steps.echo "** formatStages() **" } + if (logTest(1)) { steps.echo "** formatStages() **" } List stagesList = [] criteria.each { criterion, data -> data[_repos].each { repo, params -> @@ -202,7 +202,7 @@ class ConfigParser extends JenkinsDefinitions implements Serializable { stagesList.add(stageMap) } } - if (_DEBUG_) { steps.echo "stagesList:\n$stagesList" } + if (logTest(1)) { steps.echo "stagesList:\n$stagesList" } return stagesList } diff --git a/src/eu/indigo/scm/Git.groovy b/src/eu/indigo/scm/Git.groovy index 6a7827a1..fcdd9331 100644 --- a/src/eu/indigo/scm/Git.groovy +++ b/src/eu/indigo/scm/Git.groovy @@ -26,12 +26,12 @@ class Git extends JenkinsDefinitions implements Serializable { } def checkoutRepository() { - if (_DEBUG_) { steps.echo "** Git.checkoutRepository() **" } + if (logTest(1)) { steps.echo "** Git.checkoutRepository() **" } steps.checkout steps.scm } - def checkoutRepository(String repository, String branch='master', String credentialsId) { - if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } + def checkoutRepository(String repository, String credentialsId, String name='origin', String refspec='+refs/heads/*:refs/remotes/origin/*', String branch='master', String relativeTargetDir='.') { + if (logTest(1)) { steps.echo "** Git.checkoutRepository($repository, $branch, $name, $refspec, $relativeTargetDir, $credentialsId) **" } steps.checkout transformGitSCM([ branches: [[name: "*/${branch}"]], extensions: steps.scm.extensions + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'], diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index a3ba51c8..c337d443 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -14,23 +14,29 @@ class GitLocalBranch extends Git implements Serializable { @Override def checkoutRepository() { - if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } + if (logTest(1)) { + steps.echo """** GitLocalBranch.checkoutRepository() default values: + credentialsId: ${steps.scm.userRemoteConfigs[0].credentialsId} + url: ${steps.scm.userRemoteConfigs[0].url} + name: ${steps.scm.userRemoteConfigs[0].name} + refspec: ${steps.scm.userRemoteConfigs[0].refspec} **""" + } steps.checkout transformGitSCM([ branches: steps.scm.branches, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: steps.scm.userRemoteConfigs + userRemoteConfigs: [[credentialsId: steps.scm.userRemoteConfigs[0].credentialsId, url: steps.scm.userRemoteConfigs[0].url, name: steps.scm.userRemoteConfigs[0].name, refspec: steps.scm.userRemoteConfigs[0].refspec]] ]) } @Override - def checkoutRepository(String repository, String branch='master', String credentialsId) { - if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } + def checkoutRepository(String repository, String credentialsId, String name='origin', String refspec='+refs/heads/*:refs/remotes/origin/*', String branch='master', String relativeTargetDir='.') { + if (logTest(1)) { steps.echo "** GitLocalBranch.checkoutRepository($repository, $branch, $name, $refspec, $relativeTargetDir, $credentialsId) **" } steps.checkout transformGitSCM([ branches: [[name: "*/${branch}"]], extensions: steps.scm.extensions + - [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'] + + [$class: 'RelativeTargetDirectory', relativeTargetDir: relativeTargetDir] + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [[url: repository, credentialsId: credentialsId]] + userRemoteConfigs: [[url: repository, credentialsId: credentialsId, name: name, refspec: refspec]] ]) }