This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec864e8
commit 5da7a40
Showing
5 changed files
with
96 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.wooga.jenkins.pipeline.check | ||
|
||
import net.wooga.jenkins.pipeline.check.steps.PackedStep | ||
import net.wooga.jenkins.pipeline.config.Platform | ||
import net.wooga.jenkins.pipeline.model.Docker | ||
|
||
class Nodes { | ||
|
||
private Object jenkins | ||
private Docker docker | ||
private EnclosureCreator enclosureCreator | ||
|
||
Nodes(Object jenkins, Docker docker, EnclosureCreator enclosureCreator) { | ||
this.jenkins = jenkins | ||
this.docker = docker | ||
this.enclosureCreator = enclosureCreator | ||
} | ||
|
||
def withDocker(Platform platform, PackedStep mainCls, Closure catchCls = {throw it}, PackedStep finallyCls = {}) { | ||
return enclosureCreator.atlasNode(platform.name, | ||
platform.generateTestLabelsString(), | ||
platform.testEnvironment, | ||
withCheckout(platform.checkoutDirectory, { docker.runOnImage(mainCls) }), | ||
catchCls, | ||
withCleanup(platform.clearWs, finallyCls) | ||
) | ||
} | ||
|
||
def simple(Platform platform, PackedStep mainClosure, Closure catchCls = {throw it}, PackedStep finallyCls = {}) { | ||
return enclosureCreator.atlasNode(platform.name, | ||
platform.generateTestLabelsString(), | ||
platform.testEnvironment, | ||
withCheckout(platform.checkoutDirectory, mainClosure), | ||
catchCls, | ||
withCleanup(platform.clearWs, finallyCls) | ||
) | ||
} | ||
|
||
private PackedStep withCheckout(String checkoutDir, PackedStep step) { | ||
return { | ||
jenkins.dir(checkoutDir) { | ||
jenkins.checkout(jenkins.scm) | ||
} | ||
step() | ||
} | ||
} | ||
|
||
private PackedStep withCleanup(boolean hasCleanup, PackedStep step) { | ||
return { | ||
step() | ||
if(hasCleanup) { | ||
jenkins.cleanWs() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,53 @@ | ||
package net.wooga.jenkins.pipeline.model | ||
|
||
import com.cloudbees.groovy.cps.NonCPS | ||
|
||
class EnvVars { | ||
|
||
final Map<String, Closure<String>> environment | ||
final List<?> environment | ||
|
||
static EnvVars fromList(List<?> env) { | ||
return new EnvVars(env) | ||
} | ||
|
||
EnvVars(List<?> environment) { | ||
this.environment = environment | ||
} | ||
|
||
EnvVars(Map<String, ?> environment) { | ||
this.environment = lazifyMap(environment) | ||
|
||
List<String> resolveAsStrings() { | ||
return environment.collect { | ||
if(it instanceof Closure) { | ||
return it.call().toString() | ||
} | ||
return it.toString() | ||
} | ||
} | ||
|
||
static Map<String, Closure<String>> lazifyMap(Map<String, ?> env) { | ||
// def mapToTuples(Map map) { | ||
// return map.collect { new Tuple2<>(it.key, it.value) } | ||
// } | ||
@NonCPS | ||
List<List<?>>mapToList(Map map){ | ||
return map.collect { it ->[it.key, it.value]} | ||
} | ||
|
||
|
||
static Map<String, Closure> lazifyMap(Map<String, ?> env) { | ||
Map<String, Closure<String>> lazyMap = [:] | ||
for(String key : env.keySet()) { | ||
for(String key in env.keySet()) { | ||
if(env[key] instanceof Closure) { | ||
lazyMap.put(key, env[key]) | ||
} else { | ||
def value = env.get(key) | ||
lazyMap.put(key, { -> value }) | ||
lazyMap.put(key, { -> value?.toString() }) | ||
} | ||
} | ||
return lazyMap | ||
} | ||
|
||
List<String> resolveAsStrings() { | ||
List<String> result = [] | ||
for(String key : environment.keySet()) { | ||
Closure<String> lazyValue = environment[key] | ||
def value = lazyValue?.call() | ||
if(value != null) { | ||
result += ["$key=$value"] | ||
} | ||
} | ||
return result | ||
} | ||
|
||
Closure<String> getAt(String key) { | ||
environment[key] | ||
Object getAt(String key) { | ||
environment.find{ it.first == key } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters