Skip to content

Commit fed41bb

Browse files
committed
adds workingDir convention
1 parent e0707c0 commit fed41bb

File tree

5 files changed

+111
-71
lines changed

5 files changed

+111
-71
lines changed

src/net/wooga/jenkins/pipeline/assemble/Assemblers.groovy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.wooga.jenkins.pipeline.assemble
22

3+
import net.wooga.jenkins.pipeline.config.PipelineConventions
34
import net.wooga.jenkins.pipeline.model.Gradle
45

56
class Assemblers {
@@ -16,11 +17,14 @@ class Assemblers {
1617
this.gradle = gradle
1718
}
1819

19-
def unityWDK(String unityLogCategory, String releaseType, String releaseScope) {
20-
jenkins.withEnv(["UNITY_LOG_CATEGORY = ${unityLogCategory}"]) {
21-
gradle.wrapper("-Prelease.stage=${releaseType.trim()} -Prelease.scope=${releaseScope.trim()} assemble")
20+
def unityWDK(String unityLogCategory, String releaseType, String releaseScope, PipelineConventions conventions) {
21+
String workingDir = conventions.workingDir
22+
jenkins.dir(workingDir) {
23+
jenkins.withEnv(["UNITY_LOG_CATEGORY = ${unityLogCategory}"]) {
24+
gradle.wrapper("-Prelease.stage=${releaseType.trim()} -Prelease.scope=${releaseScope.trim()} assemble")
25+
}
2226
}
23-
return jenkins.findFiles(glob: 'build/outputs/*.nupkg')[0]
27+
return jenkins.findFiles(glob: "$workingDir/build/outputs/*.nupkg")[0]
2428
}
2529

2630
}

src/net/wooga/jenkins/pipeline/config/PipelineConventions.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class PipelineConventions implements Cloneable {
2020
this.javaParallelPrefix = other.javaParallelPrefix
2121
this.wdkParallelPrefix = other.wdkParallelPrefix
2222
this.wdkCoberturaFile = other.wdkCoberturaFile
23+
this.workingDir = other.workingDir
2324
}
2425

2526
PipelineConventions mergeWithConfigMap(Map configMap) {
@@ -33,6 +34,7 @@ class PipelineConventions implements Cloneable {
3334
it.wdkParallelPrefix = configMap.wdkParallelPrefix?: it.wdkParallelPrefix
3435
it.wdkCoberturaFile = configMap.wdkCoberturaFile?: it.wdkCoberturaFile
3536
it.wdkSetupStashId = configMap.wdkSetupStashId?: it.wdkSetupStashId
37+
it.workingDir = configMap.workingDir?: it.workingDir
3638
return it
3739
}
3840
}
@@ -47,6 +49,8 @@ class PipelineConventions implements Cloneable {
4749
String wdkParallelPrefix = "check "
4850
String wdkCoberturaFile = '**/codeCoverage/Cobertura.xml'
4951
String wdkSetupStashId = 'setup_w'
52+
53+
String workingDir = '.'
5054
}
5155

5256
class ImmutablePipelineConventions extends PipelineConventions {

src/net/wooga/jenkins/pipeline/publish/Publishers.groovy

Lines changed: 87 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,68 @@ class Publishers {
2222
}
2323

2424
def gradlePlugin(String publishKeySecret, String publishSecretSecret,
25-
String checkTask = PipelineConventions.standard.checkTask) {
26-
jenkins.withCredentials([jenkins.string(credentialsId: publishKeySecret, variable: "GRADLE_PUBLISH_KEY"),
27-
jenkins.string(credentialsId: publishSecretSecret, variable: "GRADLE_PUBLISH_SECRET")]) {
28-
gradle.wrapper("${releaseType} " +
29-
"-Pgradle.publish.key=${jenkins.GRADLE_PUBLISH_KEY} " +
30-
"-Pgradle.publish.secret=${jenkins.GRADLE_PUBLISH_SECRET} " +
31-
"-Prelease.stage=${releaseType} " +
32-
"-Prelease.scope=${releaseScope} -x ${checkTask}")
25+
PipelineConventions conventions = PipelineConventions.standard) {
26+
String checkTask = conventions.checkTask
27+
String workingDir = conventions.workingDir
28+
jenkins.dir(workingDir) {
29+
jenkins.withCredentials([jenkins.string(credentialsId: publishKeySecret, variable: "GRADLE_PUBLISH_KEY"),
30+
jenkins.string(credentialsId: publishSecretSecret, variable: "GRADLE_PUBLISH_SECRET")]) {
31+
gradle.wrapper("${releaseType} " +
32+
"-Pgradle.publish.key=${jenkins.GRADLE_PUBLISH_KEY} " +
33+
"-Pgradle.publish.secret=${jenkins.GRADLE_PUBLISH_SECRET} " +
34+
"-Prelease.stage=${releaseType} " +
35+
"-Prelease.scope=${releaseScope} -x ${checkTask}")
36+
}
3337
}
3438
}
3539

36-
def bintray(String bintraySecret, String checkTask = PipelineConventions.standard.checkTask) {
37-
jenkins.withCredentials([jenkins.usernamePassword(credentialsId: bintraySecret, usernameVariable: "BINTRAY_USER",
38-
passwordVariable: "BINTRAY_API_KEY")]) {
39-
gradle.wrapper("${releaseType} " +
40+
def bintray(String bintraySecret, PipelineConventions conventions = PipelineConventions.standard) {
41+
String checkTask = conventions.checkTask
42+
String workingDir = conventions.workingDir
43+
jenkins.dir(workingDir) {
44+
jenkins.withCredentials([jenkins.usernamePassword(credentialsId: bintraySecret, usernameVariable: "BINTRAY_USER",
45+
passwordVariable: "BINTRAY_API_KEY")]) {
46+
gradle.wrapper("${releaseType} " +
4047
"-Pbintray.user=${jenkins.BINTRAY_USER} " +
4148
"-Pbintray.key=${jenkins.BINTRAY_API_KEY} " +
4249
"-Prelease.stage=${releaseType} " +
4350
"-Prelease.scope=${releaseScope} -x ${checkTask}")
51+
}
4452
}
4553
}
4654

47-
def ossrh(String publishSecret, String signingKeySecret, String signingKeyIdSecret, String signingPassphraseSecret,
48-
String checkTask = PipelineConventions.standard.checkTask) {
49-
def credentials = [jenkins.usernamePassword(credentialsId: publishSecret,
50-
usernameVariable:"OSSRH_USERNAME", passwordVariable: "OSSRH_PASSWORD")] +
51-
ossrhSigningCredentials(signingKeySecret, signingKeyIdSecret, signingPassphraseSecret)
52-
jenkins.withCredentials(credentials) {
53-
gradle.wrapper("${releaseType} " +
54-
"-Prelease.stage=${releaseType} " +
55-
"-Prelease.scope=${releaseScope} -x ${checkTask}")
55+
def ossrh(String publishSecret, String signingKeySecret, String signingKeyIdSecret, String signingPassphraseSecret, PipelineConventions conventions = PipelineConventions.standard) {
56+
String checkTask = conventions.checkTask
57+
String workingDir = conventions.workingDir
58+
jenkins.dir(workingDir) {
59+
def credentials = [jenkins.usernamePassword(credentialsId: publishSecret,
60+
usernameVariable: "OSSRH_USERNAME", passwordVariable: "OSSRH_PASSWORD")] +
61+
ossrhSigningCredentials(signingKeySecret, signingKeyIdSecret, signingPassphraseSecret)
62+
jenkins.withCredentials(credentials) {
63+
gradle.wrapper("${releaseType} " +
64+
"-Prelease.stage=${releaseType} " +
65+
"-Prelease.scope=${releaseScope} -x ${checkTask}")
66+
}
5667
}
5768
}
5869

5970
def artifactoryOSSRH(String artifactorySecret,
60-
String signingKeySecret, String signingKeyIdSecret, String signingPassphraseSecret,
61-
String checkTask = PipelineConventions.standard.checkTask) {
62-
def credentials = [
63-
jenkins.usernamePassword(credentialsId: artifactorySecret,
64-
usernameVariable:"ARTIFACTORY_USER",
65-
passwordVariable: "ARTIFACTORY_PASS")
66-
] + ossrhSigningCredentials(signingKeySecret, signingKeyIdSecret, signingPassphraseSecret)
67-
jenkins.withCredentials(credentials) {
68-
gradle.wrapper("${releaseType} " +
69-
"-Partifactory.user=${jenkins.ARTIFACTORY_USER} " +
70-
"-Partifactory.password=${jenkins.ARTIFACTORY_PASS} " +
71-
"-Prelease.stage=${releaseType} " +
72-
"-Prelease.scope=${releaseScope} -x ${checkTask}")
71+
String signingKeySecret, String signingKeyIdSecret, String signingPassphraseSecret) {
72+
String checkTask = conventions.checkTask
73+
String workingDir = conventions.workingDir
74+
jenkins.dir(workingDir) {
75+
def credentials = [
76+
jenkins.usernamePassword(credentialsId: artifactorySecret,
77+
usernameVariable: "ARTIFACTORY_USER",
78+
passwordVariable: "ARTIFACTORY_PASS")
79+
] + ossrhSigningCredentials(signingKeySecret, signingKeyIdSecret, signingPassphraseSecret)
80+
jenkins.withCredentials(credentials) {
81+
gradle.wrapper("${releaseType} " +
82+
"-Partifactory.user=${jenkins.ARTIFACTORY_USER} " +
83+
"-Partifactory.password=${jenkins.ARTIFACTORY_PASS} " +
84+
"-Prelease.stage=${releaseType} " +
85+
"-Prelease.scope=${releaseScope} -x ${checkTask}")
86+
}
7387
}
7488
}
7589

@@ -82,41 +96,54 @@ class Publishers {
8296
}
8397

8498
def unityArtifactoryPaket(String unityPath, String artifactorySecret,
85-
String checkTask = PipelineConventions.standard.checkTask) {
86-
jenkins.withEnv(["UNITY_PACKAGE_MANAGER = paket", "UNITY_PATH=${unityPath}", "UNITY_LOG_CATEGORY=build"]) {
87-
jenkins.withCredentials([jenkins.usernameColonPassword(credentialsId: artifactorySecret, variable: "NUGET_KEY"),
88-
jenkins.usernameColonPassword(credentialsId: artifactorySecret, variable: "nugetkey")]) {
89-
gradle.wrapper("${releaseType} " +
90-
"-Prelease.stage=${releaseType} " +
91-
"-Ppaket.publish.repository='${releaseType}' " +
92-
"-Prelease.scope=${releaseScope} -x ${checkTask}")
99+
PipelineConventions conventions = PipelineConventions.standard) {
100+
String checkTask = conventions.checkTask
101+
String workingDir = conventions.workingDir
102+
jenkins.dir(workingDir) {
103+
jenkins.withEnv(["UNITY_PACKAGE_MANAGER = paket", "UNITY_PATH=${unityPath}", "UNITY_LOG_CATEGORY=build"]) {
104+
jenkins.withCredentials([jenkins.usernameColonPassword(credentialsId: artifactorySecret, variable: "NUGET_KEY"),
105+
jenkins.usernameColonPassword(credentialsId: artifactorySecret, variable: "nugetkey")]) {
106+
gradle.wrapper("${releaseType} " +
107+
"-Prelease.stage=${releaseType} " +
108+
"-Ppaket.publish.repository='${releaseType}' " +
109+
"-Prelease.scope=${releaseScope} -x ${checkTask}")
110+
}
93111
}
94112
}
95113
}
96114

97-
def npm(String npmCredsSecret) {
98-
def credentials = [
99-
jenkins.usernamePassword(credentialsId: npmCredsSecret,
100-
usernameVariable:"NODE_RELEASE_NPM_USER",
101-
passwordVariable: "NODE_RELEASE_NPM_PASS")
102-
]
103-
jenkins.withCredentials(credentials) {
104-
gradle.wrapper("${releaseType} -Prelease.stage=${releaseType} -Prelease.scope=${releaseScope} -x check")
115+
def npm(String npmCredsSecret,
116+
PipelineConventions conventions = PipelineConventions.standard) {
117+
String checkTask = conventions.checkTask
118+
String workingDir = conventions.workingDir
119+
jenkins.dir(workingDir) {
120+
def credentials = [
121+
jenkins.usernamePassword(credentialsId: npmCredsSecret,
122+
usernameVariable: "NODE_RELEASE_NPM_USER",
123+
passwordVariable: "NODE_RELEASE_NPM_PASS")
124+
]
125+
jenkins.withCredentials(credentials) {
126+
gradle.wrapper("${releaseType} -Prelease.stage=${releaseType} -Prelease.scope=${releaseScope} -x ${checkTask}")
127+
}
105128
}
106129
}
107130

108-
def unityArtifactoryUpm(String artifactorySecret) {
109-
jenkins.withEnv(["UNITY_PACKAGE_MANAGER = upm", "UNITY_LOG_CATEGORY=build"]) {
110-
jenkins.withCredentials([jenkins.usernamePassword(credentialsId: artifactorySecret, usernameVariable:"UPM_USERNAME", passwordVariable: "UPM_PASSWORD"),
111-
jenkins.usernameColonPassword(credentialsId: artifactorySecret, variable: "NUGET_KEY"),
112-
jenkins.usernameColonPassword(credentialsId: artifactorySecret, variable: "nugetkey")]) {
131+
def unityArtifactoryUpm(String artifactorySecret,
132+
PipelineConventions conventions = PipelineConventions.standard) {
133+
String workingDir = conventions.workingDir
134+
jenkins.dir(workingDir) {
135+
jenkins.withEnv(["UNITY_PACKAGE_MANAGER = upm", "UNITY_LOG_CATEGORY=build"]) {
136+
jenkins.withCredentials([jenkins.usernamePassword(credentialsId: artifactorySecret, usernameVariable: "UPM_USERNAME", passwordVariable: "UPM_PASSWORD"),
137+
jenkins.usernameColonPassword(credentialsId: artifactorySecret, variable: "NUGET_KEY"),
138+
jenkins.usernameColonPassword(credentialsId: artifactorySecret, variable: "nugetkey")]) {
113139

114140

115-
gradle.wrapper("publish " +
116-
"-Ppaket.publish.repository='${releaseType}' " +
117-
"-Ppublish.repository='${releaseType}' " +
118-
"-PversionBuilder.stage=${releaseType} " +
119-
"-PversionBuilder.scope=${releaseScope}")
141+
gradle.wrapper("publish " +
142+
"-Ppaket.publish.repository='${releaseType}' " +
143+
"-Ppublish.repository='${releaseType}' " +
144+
"-PversionBuilder.stage=${releaseType} " +
145+
"-PversionBuilder.scope=${releaseScope}")
146+
}
120147
}
121148
}
122149
}

src/net/wooga/jenkins/pipeline/setup/Setups.groovy

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ class Setups {
1818
return new Setups(jenkinsScript, gradle)
1919
}
2020

21-
def wdk(String releaseType, String releaseScope, String setupTask = PipelineConventions.standard.setupTask) {
22-
gradle.wrapper("-Prelease.stage=${releaseType.trim()} " +
23-
"-Prelease.scope=${releaseScope.trim()} ${setupTask}")
21+
def wdk(String releaseType, String releaseScope, PipelineConventions conventions = PipelineConventions.standard) {
22+
String setupTask = conventions.setupTask
23+
String workingDir = conventions.workingDir
24+
jenkins.dir(workingDir) {
25+
gradle.wrapper("-Prelease.stage=${releaseType.trim()} " +
26+
"-Prelease.scope=${releaseScope.trim()} ${setupTask}")
27+
}
28+
2429
}
2530

2631
}

vars/buildUnityWdkV2.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def call(Map configMap = [unityVersions: []]) {
7474
env.RELEASE_STAGE = params.RELEASE_STAGE?: defaultReleaseType
7575
env.RELEASE_SCOPE = params.RELEASE_SCOPE?: defaultReleaseScope
7676
def setup = config.pipelineTools.setups
77-
setup.wdk(env.RELEASE_STAGE as String, env.RELEASE_SCOPE as String)
77+
setup.wdk(env.RELEASE_STAGE as String, env.RELEASE_SCOPE as String, config.conventions)
7878
}
7979
}
8080
post {
@@ -109,7 +109,7 @@ def call(Map configMap = [unityVersions: []]) {
109109
env.RELEASE_STAGE = params.RELEASE_STAGE?: defaultReleaseType
110110
env.RELEASE_SCOPE = params.RELEASE_SCOPE?: defaultReleaseScope
111111
def setup = config.pipelineTools.setups
112-
setup.wdk(env.RELEASE_STAGE as String, env.RELEASE_SCOPE as String)
112+
setup.wdk(env.RELEASE_STAGE as String, env.RELEASE_SCOPE as String, config.conventions)
113113
}
114114
}
115115
post {
@@ -176,7 +176,7 @@ def call(Map configMap = [unityVersions: []]) {
176176
unstash 'upm_setup_w'
177177
script {
178178
def assembler = config.pipelineTools.assemblers
179-
assembler.unityWDK("build", env.RELEASE_STAGE as String, env.RELEASE_SCOPE as String)
179+
assembler.unityWDK("build", env.RELEASE_STAGE as String, env.RELEASE_SCOPE as String, config.conventions)
180180
}
181181
}
182182

@@ -244,7 +244,7 @@ def call(Map configMap = [unityVersions: []]) {
244244
unstash 'wdk_output'
245245
script {
246246
def publisher = config.pipelineTools.createPublishers(env.RELEASE_STAGE, env.RELEASE_SCOPE)
247-
publisher.unityArtifactoryUpm('artifactory_publish')
247+
publisher.unityArtifactoryUpm('artifactory_publish', config.conventions)
248248
}
249249
}
250250

0 commit comments

Comments
 (0)