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

Opinionations are now on scripts on vars/ dir #130

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
}
testImplementation "org.jenkins-ci.main:jenkins-test-harness:2.71"
testImplementation 'com.github.ben-manes.caffeine:caffeine:2.9.2'
testImplementation 'org.powermock:powermock-classloading-xstream:2.0.9'
}


Expand Down
3 changes: 2 additions & 1 deletion src/net/wooga/jenkins/pipeline/BuildVersion.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class BuildVersion {
}

final String version
@Deprecated
final Boolean optional
// net_4_6, net_standard_2_0 (DEFAULT)
final String apiCompatibilityLevel
Expand All @@ -58,7 +59,7 @@ class BuildVersion {
}

@NonCPS
String toLabel(){
String toLabel() {
def result = version
if (optional){
result += " (optional)"
Expand Down
2 changes: 1 addition & 1 deletion src/net/wooga/jenkins/pipeline/PipelineTools.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PipelineTools {
def gradle = Gradle.fromJenkins(jenkins, config.gradleArgs)
def docker = Docker.fromJenkins(jenkins, config.dockerArgs)
def setups = Setups.create(jenkins, gradle)
def checks = Checks.create(jenkins, docker, gradle, config.metadata.buildNumber)
def checks = Checks.create(jenkins, docker, config.metadata.buildNumber)
def assemblers = Assemblers.fromJenkins(jenkins, gradle)
def publishersFactory = {
String releaseType, String releaseScope -> Publishers.fromJenkins(jenkins, gradle, releaseType, releaseScope)
Expand Down
61 changes: 0 additions & 61 deletions src/net/wooga/jenkins/pipeline/check/CheckCreator.groovy

This file was deleted.

57 changes: 27 additions & 30 deletions src/net/wooga/jenkins/pipeline/check/Checks.groovy
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
package net.wooga.jenkins.pipeline.check

import net.wooga.jenkins.pipeline.check.steps.GradleSteps
import net.wooga.jenkins.pipeline.check.steps.Step
import net.wooga.jenkins.pipeline.config.Platform
import net.wooga.jenkins.pipeline.model.Docker
import net.wooga.jenkins.pipeline.model.Gradle

class Checks {
final Object jenkins
final Enclosures enclosures

Docker docker
Gradle gradle
GradleSteps steps
EnclosureCreator enclosureCreator
Enclosures enclosures
CheckCreator checkCreator

//jenkins CPS-transformations doesn't work inside constructors, so we have to keep these as simple as possible.
//for non-trivial constructors, prefer static factories.
static Checks create(Object jenkinsScript, Docker docker, Gradle gradle, int buildNumber) {
static Checks create(Object jenkinsScript, Docker docker, int buildNumber) {
def enclosureCreator = new EnclosureCreator(jenkinsScript, buildNumber)
def enclosures = new Enclosures(jenkinsScript, docker, enclosureCreator)
def checkCreator = new CheckCreator(jenkinsScript, enclosures)
def steps = new GradleSteps(jenkinsScript, gradle)

return new Checks(docker, gradle, steps, enclosureCreator, enclosures, checkCreator)
return new Checks(jenkinsScript, enclosures)
}

private Checks(Docker docker, Gradle gradle, GradleSteps steps, EnclosureCreator enclosureCreator,
Enclosures enclosures, CheckCreator checkCreator) {
this.docker = docker
this.gradle = gradle
this.steps = steps
this.enclosureCreator = enclosureCreator
public Checks(Object jenkinsScript, Enclosures enclosures) {
this.jenkins = jenkinsScript
this.enclosures = enclosures
this.checkCreator = checkCreator
}

JavaChecks forJavaPipelines() {
return new JavaChecks(checkCreator, steps)
Step enclosedSimpleCheck(Step testStep, Step analysisStep, Closure catchClosure, Closure finallyClosure) {
return simpleCheck(testStep, analysisStep).wrappedBy { checkStep, platform ->
def enclosedPackedStep = platform.runsOnDocker ?
enclosures.withDocker(platform, checkStep.pack(platform), catchClosure, finallyClosure) :
enclosures.simple(platform, checkStep.pack(platform), catchClosure, finallyClosure)
enclosedPackedStep()
}
}

WDKChecks forWDKPipelines() {
return new WDKChecks(checkCreator, steps)
Step simpleCheck(Step testStep, Step analysisStep) {
return new Step({ Platform platform ->
jenkins.dir(platform.checkDirectory) {
testStep(platform)
if (platform.isMain()) {
analysisStep(platform)
}
}
})
}

JSChecks forJSPipelines() {
return new JSChecks(checkCreator, steps)
}

}


19 changes: 0 additions & 19 deletions src/net/wooga/jenkins/pipeline/check/Coveralls.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.wooga.jenkins.pipeline.check

import net.wooga.jenkins.pipeline.model.Gradle

class Coveralls {

final Object jenkins
Expand All @@ -12,23 +10,6 @@ class Coveralls {
this.token = token
}

void maybeRun(Gradle gradle, String task) {
if (token) {
jenkins.withEnv(["COVERALLS_REPO_TOKEN=${token}"]) {
gradle.wrapper(task)
jenkins.publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'build/reports/jacoco/test/html',
reportFiles: 'index.html',
reportName: "Coverage ${it}",
reportTitles: ''
])
}
}
}

boolean equals(o) {
if (this.is(o)) return true
if (getClass() != o.class) return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EnclosureCreator {
this.buildNumber = buildNumber
}

Closure withNodeAndEnv(Platform platform, PackedStep mainCls, Closure catchCls, PackedStep finallyCls) {
Closure nodeForPlatform(Platform platform, PackedStep mainCls, Closure catchCls, PackedStep finallyCls) {
def testEnvironment = platform.testEnvironment +
["TRAVIS_JOB_NUMBER=${buildNumber}.${platform.name.toUpperCase()}"]
return {
Expand Down
22 changes: 17 additions & 5 deletions src/net/wooga/jenkins/pipeline/check/Enclosures.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ class Enclosures {
}

def withDocker(Platform platform, PackedStep mainCls, Closure catchCls = {throw it}, PackedStep finallyCls = {}) {
return enclosureCreator.withNodeAndEnv(platform,
return enclosureCreator.nodeForPlatform(platform,
withCheckout(platform.checkoutDirectory, { docker.runOnImage(mainCls) }),
catchCls,
withOptional(platform.name, platform.optional, catchCls),
withCleanup(platform.clearWs, finallyCls)
)
}

def simple(Platform platform, PackedStep mainClosure, Closure catchCls = {throw it}, PackedStep finallyCls = {}) {
return enclosureCreator.withNodeAndEnv(platform,
return enclosureCreator.nodeForPlatform(platform,
withCheckout(platform.checkoutDirectory, mainClosure),
catchCls,
withOptional(platform.name, platform.optional, catchCls),
withCleanup(platform.clearWs, finallyCls)
)
}
Expand All @@ -36,8 +36,8 @@ class Enclosures {
return {
jenkins.dir(checkoutDir) {
jenkins.checkout(jenkins.scm)
step()
}
step()
}
}

Expand All @@ -49,4 +49,16 @@ class Enclosures {
}
}
}


//TODO tests
private Closure withOptional(String name, boolean isOptional, Closure catchCls) {
return { exception ->
if (isOptional) {
jenkins.unstable(message: "Optional run ${name} failed, continuing other runs\n${exception.toString()}")
} else {
catchCls(exception)
}
}
}
}
53 changes: 0 additions & 53 deletions src/net/wooga/jenkins/pipeline/check/JSChecks.groovy

This file was deleted.

52 changes: 0 additions & 52 deletions src/net/wooga/jenkins/pipeline/check/JavaChecks.groovy

This file was deleted.

10 changes: 0 additions & 10 deletions src/net/wooga/jenkins/pipeline/check/Sonarqube.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.wooga.jenkins.pipeline.check

import net.wooga.jenkins.pipeline.model.Gradle

class Sonarqube {

final String token
Expand All @@ -10,14 +8,6 @@ class Sonarqube {
this.token = token
}

void maybeRun(Gradle gradle, String task, String branchName="") {
if(token != null) {
branchName = branchName == null? "" : branchName
gradle.wrapper(task + " -Dsonar.login=${token}" +
" -Pgithub.branch.name=${branchName.trim()}" as String)
}
}

boolean equals(o) {
if (this.is(o)) return true
if (getClass() != o.class) return false
Expand Down
Loading