Skip to content

Commit b7fcd5f

Browse files
committed
mavenIntegrationTest: allow overriding mvn commands
This patch allows the `mavenCI{}` to over maven command in order to allow `mavenIntegrationTes{}` to pass specific command to execute. This patch adds `runTestsInUserNamespace` to use username namespace as defualt default environment to run Integration Tests. Fixes: openshiftio/openshift.io#763 Fixes: openshiftio/openshift.io#3134 Related to: fabric8io#412
1 parent 92fc97e commit b7fcd5f

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

ReadMe.md

+17-10
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ NOTE: if `cmd` is set, `goal`, `profile`, `skipTests` will have no effect.
212212
itestPattern = '*KT'
213213
}
214214
```
215+
- pass `cmd` parameter to override the `mvn` command to execute in integration test
216+
```groovy
217+
mavenIntegrationTest {
218+
integrationTestCmd = 'mvn -P openshift-it org.apache.maven.plugins:maven-failsafe-plugin:verify'
219+
}
220+
```
221+
Note: All other flags are ignored if `mavenIntegrationTest` has `integrationTestCmd` parameter.
215222
#### Merge and Wait for Pull Request
216223

217224
- adds a [merge] comment to a github pull request
@@ -248,7 +255,7 @@ NOTE: if `cmd` is set, `goal`, `profile`, `skipTests` will have no effect.
248255
}
249256
```
250257
#### Update Maven Property Version
251-
During a release involving multiple java projects we often need to update downstream maven poms with new versions of a dependency. In a release pipeline we want to automate this, set up a pull request and let CI run to make sure there's no conflicts.
258+
During a release involving multiple java projects we often need to update downstream maven poms with new versions of a dependency. In a release pipeline we want to automate this, set up a pull request and let CI run to make sure there's no conflicts.
252259

253260
- performs a search and replace in the maven pom
254261
- finds the latest version available in maven central (repo is configurable)
@@ -274,7 +281,7 @@ Automating this has saved us a lot of time during the release pipeline
274281
}
275282
```
276283
#### Wait Until Artifact Synced With Maven Central
277-
When working with open source java projects we need to stage artifacts with OSS Sonatype in order to promote them into maven central. This can take 10-30 mins depending on the size of the artifacts being synced.
284+
When working with open source java projects we need to stage artifacts with OSS Sonatype in order to promote them into maven central. This can take 10-30 mins depending on the size of the artifacts being synced.
278285

279286
A useful thing is to be notified in chat when artifacts are available in maven central as blocking the pipeine until we're sure the promote has worked.
280287

@@ -324,7 +331,7 @@ When a project is staged an array is returned and passed around functions furthe
324331
}
325332
```
326333

327-
One other important note is on the fabric8 project we don't use the maven release plugin or update to next SNAPSHOT versions as it causes unwanted noise and commits to our many github repos. Instead we use a fixed development `x.x-SNAPSHOT` version so we can easily work in development on multiple projects that have maven dependencies with each other.
334+
One other important note is on the fabric8 project we don't use the maven release plugin or update to next SNAPSHOT versions as it causes unwanted noise and commits to our many github repos. Instead we use a fixed development `x.x-SNAPSHOT` version so we can easily work in development on multiple projects that have maven dependencies with each other.
328335

329336
Now that we don't store the next release version in the poms we need to figure it out during the release. Rather than store the version number in the repo which involves a commit and not too CD friendly (i.e. would trigger another release just for the version update) we use the `git tag`. From this we can get the previous release version, increment it and push it back without triggering another release. This seems a bit strange but it has been holding up and has significantly reduced unwanted SCM commits related to maven releases.
330337

@@ -389,8 +396,8 @@ Now that we don't store the next release version in the poms we need to figure i
389396
```
390397
#### Git Tag
391398

392-
- tags the current git repo with the provided version
393-
- pushes the tag to the remote repository
399+
- tags the current git repo with the provided version
400+
- pushes the tag to the remote repository
394401

395402
```groovy
396403
gitTag {
@@ -415,9 +422,9 @@ __NOTE__ in order for images to be found by the remote OpenShift instance it mus
415422

416423
#### Deploy Remote Kubernetes
417424

418-
Deploys the staged fabric8 release to a remote Kubernetes cluster
425+
Deploys the staged fabric8 release to a remote Kubernetes cluster
419426

420-
__NOTE__ in order for images to be found by the remote OpenShift instance it must be able to pull images from the staging docker registry. Noting private networks and insecure-registry flags.
427+
__NOTE__ in order for images to be found by the remote OpenShift instance it must be able to pull images from the staging docker registry. Noting private networks and insecure-registry flags.
421428

422429
```groovy
423430
node {
@@ -587,7 +594,7 @@ For this case you can combine add the docker template and the maven template tog
587594
node('maven-and-docker') {
588595
container(name: 'maven') {
589596
sh 'mvn clean package fabric8:build fabric8:push'
590-
}
597+
}
591598
}
592599
}
593600
}
@@ -598,7 +605,7 @@ The above is equivalent to:
598605
mavenNode(label: 'maven-and-docker') {
599606
container(name: 'maven') {
600607
sh 'mvn clean package fabric8:build fabric8:push'
601-
}
608+
}
602609
}
603610
}
604611

@@ -613,7 +620,7 @@ In the example above we can add release capabilities too, by adding the releaseT
613620
mvn release:clean release:prepare
614621
mvn clean release:perform
615622
"""
616-
}
623+
}
617624
}
618625
}
619626
}

vars/mavenCI.groovy

+9-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def call(body) {
2929
def goal = config.goal ?: "install"
3030
def profile = config.profile ?: "openshift"
3131
def skipTests = config.skipTests ?: false
32-
def cmd = config.cmd ?: "mvn clean -B -e -U ${goal} -Dmaven.test.skip=${skipTests} -P ${profile}"
32+
def buildCmd = config.buildCmd ?: "mvn clean -B -e -U ${goal} -Dmaven.test.skip=${skipTests} -P ${profile}"
3333

3434
def version = 'PR-' + getNewVersion {} + "-${env.BUILD_NUMBER}"
3535

3636
stage('Build + Unit test') {
3737
// set a unique temp version so we can download artifacts from nexus and run acceptance tests
3838
sh "mvn -U versions:set -DnewVersion=${version}"
39-
sh cmd
39+
sh buildCmd
4040
}
4141

4242
def s2iMode = utils.supportsOpenShiftS2I()
@@ -61,8 +61,15 @@ def call(body) {
6161
}
6262
}
6363

64+
if(config.runTestsInUserNamespace && config.integrationTestCmd == true) {
65+
def nameSpace = utils.getUsersNamespace()
66+
echo "Running the integration tests in the namespace: ${nameSpace}"
67+
integrationTestCmd = integrationTestCmd + " -Dnamespace.use.existing=" + nameSpace
68+
}
69+
6470
stage('Integration Testing') {
6571
mavenIntegrationTest {
72+
integrationTestCmd = config.integrationTestCmd
6673
environment = 'Test'
6774
failIfNoTests = false
6875
itestPattern = '*IT'

vars/mavenIntegrationTest.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def call(body) {
1111
def utils = new Utils()
1212
def envName = config.environment
1313
def kubeNS = "-Dfabric8.environment=${envName}"
14-
if (envName) {
15-
// lets try find the actual kubernetes namespace
14+
15+
if (envName && !integrationTestCmd) {
1616
try {
1717
def ns = utils.environmentNamespace(envName)
1818
if (ns) {
@@ -25,12 +25,12 @@ def call(body) {
2525
}
2626
}
2727

28+
def testCmd = config.integrationTestCmd ?: "mvn org.apache.maven.plugins:maven-failsafe-plugin:integration-test -P openshift-it ${kubeNS} -Dit.test=${config.itestPattern} -DfailIfNoTests=${config.failIfNoTests} org.apache.maven.plugins:maven-failsafe-plugin:verify"
2829
if (utils.isDisabledITests()) {
2930
echo "WARNING: Integration tests are current DISABLED for these pipelines!"
3031

3132
} else {
32-
sh "mvn org.apache.maven.plugins:maven-failsafe-plugin:integration-test ${kubeNS} -P openshift-it -Dit.test=${config.itestPattern} -DfailIfNoTests=${config.failIfNoTests} org.apache.maven.plugins:maven-failsafe-plugin:verify"
33-
33+
sh testCmd
3434
junitResults(body);
3535
}
3636
}

0 commit comments

Comments
 (0)