Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #116 #190

Open
wants to merge 7 commits into
base: release/2.3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/eu/indigo/JenkinsDefinitions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ 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) {
if(_DEBUG_) {
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
}
}

Expand Down
34 changes: 17 additions & 17 deletions src/eu/indigo/compose/DockerCompose.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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':
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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) {
Expand Down
38 changes: 19 additions & 19 deletions src/eu/indigo/compose/parser/ConfigParser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 [:]
Expand All @@ -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
Expand All @@ -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 ?
Expand All @@ -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]
}

Expand All @@ -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']
Expand All @@ -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 ->
Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions src/eu/indigo/scm/Git.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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: '.'],
Expand Down
18 changes: 12 additions & 6 deletions src/eu/indigo/scm/GitLocalBranch.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
])
}

Expand Down