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

Add workingDir convention #256

Open
wants to merge 4 commits into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,7 @@ class VersionPluginIntegrationSpec extends IntegrationSpec {

@Unroll("creates/updates remote branches and tags when updating from #latestVersion to #newVersion")
def "should create generic branches and tags with updated version remotely"(String newVersion, String latestVersion, String[] branches, String updateType) {
given: "a initialized git repository and latest version with its branches and tag"
def git = initializeGrGit("origin")
createRemoteBranchesIfNotExists(branches)
def latestTag = createTagIfNotExists(git, latestVersion)
latestTag.ifPresent { git.push(remote: "origin", tags: true) }
git.fetch()


and: "loaded version plugin"
given: "loaded version plugin"
buildFile << """
${applyPlugin(VersionPlugin)}
"""
Expand All @@ -53,6 +45,15 @@ class VersionPluginIntegrationSpec extends IntegrationSpec {
updateType = "${updateType}"
}"""

and: "a initialized git repository and latest version with its branches and tag"
def git = initializeGrGit("origin")
createRemoteBranchesIfNotExists(branches)
def latestTag = createTagIfNotExists(git, latestVersion)
latestTag.ifPresent { git.push(remote: "origin", tags: true) }
git.fetch()



and: "credentials in the environment"
environment.set("GRGIT_USER", this.githubRepo.userName)
environment.set("GRGIT_PASS", this.githubRepo.token)
Expand Down
13 changes: 9 additions & 4 deletions src/net/wooga/jenkins/pipeline/assemble/Assemblers.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.wooga.jenkins.pipeline.assemble

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

class Assemblers {
Expand All @@ -16,11 +17,15 @@ class Assemblers {
this.gradle = gradle
}

def unityWDK(String unityLogCategory, String releaseType, String releaseScope) {
jenkins.withEnv(["UNITY_LOG_CATEGORY = ${unityLogCategory}"]) {
gradle.wrapper("-Prelease.stage=${releaseType.trim()} -Prelease.scope=${releaseScope.trim()} assemble")
def unityWDK(String unityLogCategory, String releaseType, String releaseScope,
PipelineConventions conventions = PipelineConventions.standard) {
String workingDir = conventions.workingDir
jenkins.dir(workingDir) {
jenkins.withEnv(["UNITY_LOG_CATEGORY = ${unityLogCategory}"]) {
gradle.wrapper("-Prelease.stage=${releaseType.trim()} -Prelease.scope=${releaseScope.trim()} assemble")
}
}
return jenkins.findFiles(glob: 'build/outputs/*.nupkg')[0]
return jenkins.findFiles(glob: "$workingDir/build/outputs/*.nupkg")[0]
}

}
18 changes: 10 additions & 8 deletions src/net/wooga/jenkins/pipeline/check/CheckCreator.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class CheckCreator {
this.enclosures = enclosures
}

Closure junitCheck(Platform platform, Step testStep, Step analysisStep) {
def mainClosure = createCheck(testStep, analysisStep).pack(platform)
Closure junitCheck(String workingDir, Platform platform, Step testStep, Step analysisStep) {
def mainClosure = createCheck(workingDir, testStep, analysisStep).pack(platform)
def catchClosure = {throw it}
def finallyClosure = {
jenkins.junit allowEmptyResults: true, testResults: "**/build/test-results/**/*.xml"
Expand All @@ -26,8 +26,8 @@ class CheckCreator {
return checkStep
}

Closure csWDKChecks(UnityVersionPlatform versionBuild, Step testStep, Step analysisStep) {
def mainClosure = createCheck(testStep, analysisStep).pack(versionBuild.platform)
Closure csWDKChecks(String workingDir, UnityVersionPlatform versionBuild, Step testStep, Step analysisStep) {
def mainClosure = createCheck(workingDir, testStep, analysisStep).pack(versionBuild.platform)
def catchClosure = { Throwable e ->
if (versionBuild.optional) {
jenkins.unstable(message: "Unity build for optional version ${versionBuild.version} is found to be unstable\n${e.toString()}")
Expand All @@ -44,13 +44,15 @@ class CheckCreator {
return checkStep
}

protected Step createCheck(Step testStep, Step analysisStep) {
protected Step createCheck(String workingDir, Step testStep, Step analysisStep) {
return new Step({ Platform platform ->
jenkins.dir(platform.checkoutDirectory) {
jenkins.dir(platform.checkDirectory) {
testStep(platform)
if (platform.isMain()) {
analysisStep(platform)
jenkins.dir(workingDir) {
testStep(platform)
if (platform.isMain()) {
analysisStep(platform)
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/net/wooga/jenkins/pipeline/check/JSChecks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class JSChecks {
baseAnalysisStep.wrappedBy(checkArgs.analysisWrapper), conventions)
}

Closure check(Platform platform, Step testStep, Step analysisStep) {
return checkCreator.junitCheck(platform, testStep, analysisStep)
Closure check(Platform platform, Step testStep, Step analysisStep,
PipelineConventions conventions = PipelineConventions.standard) {
return checkCreator.junitCheck(conventions.workingDir, platform, testStep, analysisStep)
}

Map<String, Closure> parallel(Platform[] platforms, Closure checkStep,
Expand All @@ -47,7 +48,7 @@ class JSChecks {
PipelineConventions conventions = PipelineConventions.standard) {
return platforms.collectEntries { platform ->
String parallelStepName = "${conventions.javaParallelPrefix}${platform.name}"
return [(parallelStepName): check(platform, testStep, analysisStep)]
return [(parallelStepName): check(platform, testStep, analysisStep, conventions)]
}
}
}
6 changes: 3 additions & 3 deletions src/net/wooga/jenkins/pipeline/check/JavaChecks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class JavaChecks {
PipelineConventions conventions = PipelineConventions.standard) {
return platforms.collectEntries { platform ->
String parallelStepName = "${conventions.javaParallelPrefix}${platform.name}"
return [(parallelStepName): check(platform, testStep, analysisStep)]
return [(parallelStepName): check(platform, testStep, analysisStep, conventions)]
}
}

Closure check(Platform platform, Step testStep, Step analysisStep) {
return checkCreator.junitCheck(platform, testStep, analysisStep)
Closure check(Platform platform, Step testStep, Step analysisStep, PipelineConventions conventions = PipelineConventions.standard) {
return checkCreator.junitCheck(conventions.workingDir, platform, testStep, analysisStep)
}

Map<String, Closure> gradleCheckWithCoverage(Platform[] platforms, CheckArgs checkArgs, PipelineConventions conventions) {
Expand Down
7 changes: 4 additions & 3 deletions src/net/wooga/jenkins/pipeline/check/WDKChecks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class WDKChecks {
conventions)
}

Closure check(UnityVersionPlatform platform, Step testStep, Step analysisStep) {
return checkCreator.csWDKChecks(platform, testStep, analysisStep)
Closure check(UnityVersionPlatform platform, Step testStep, Step analysisStep,
PipelineConventions conventions = PipelineConventions.standard) {
return checkCreator.csWDKChecks(conventions.workingDir, platform, testStep, analysisStep)
}

Map<String, Closure> parallel(UnityVersionPlatform[] wdkPlatforms, Closure checkStep,
Expand All @@ -50,7 +51,7 @@ class WDKChecks {
Map<String, Closure> parallel(UnityVersionPlatform[] wdkPlatforms, Step testStep, Step analysisStep,
PipelineConventions conventions = PipelineConventions.standard) {
return wdkPlatforms.collectEntries { wdkPlatform ->
def checkStep = checkCreator.csWDKChecks(wdkPlatform, testStep, analysisStep)
def checkStep = checkCreator.csWDKChecks(conventions.workingDir, wdkPlatform, testStep, analysisStep)
return [("${conventions.wdkParallelPrefix}${wdkPlatform.stepDescription}".toString()): checkStep]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PipelineConventions implements Cloneable {
this.javaParallelPrefix = other.javaParallelPrefix
this.wdkParallelPrefix = other.wdkParallelPrefix
this.wdkCoberturaFile = other.wdkCoberturaFile
this.workingDir = other.workingDir
}

PipelineConventions mergeWithConfigMap(Map configMap) {
Expand All @@ -33,6 +34,7 @@ class PipelineConventions implements Cloneable {
it.wdkParallelPrefix = configMap.wdkParallelPrefix?: it.wdkParallelPrefix
it.wdkCoberturaFile = configMap.wdkCoberturaFile?: it.wdkCoberturaFile
it.wdkSetupStashId = configMap.wdkSetupStashId?: it.wdkSetupStashId
it.workingDir = configMap.workingDir?: it.workingDir
return it
}
}
Expand All @@ -47,6 +49,8 @@ class PipelineConventions implements Cloneable {
String wdkParallelPrefix = "check "
String wdkCoberturaFile = '**/codeCoverage/Cobertura.xml'
String wdkSetupStashId = 'setup_w'

String workingDir = '.'
}

class ImmutablePipelineConventions extends PipelineConventions {
Expand Down
Loading