You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A build extension and plugin that helps Maven play nicely with gitflow projects, CI servers and local development.
4
4
@@ -10,6 +10,7 @@ It does so by:
10
10
* SCM tagging builds for master and support branches. You can use the project SCM definition, or if you omit it, you can resolve the CI server's repository connection information. (Zero Maven scm configuration necessary)
11
11
* Promoting existing tested (staged) artifacts for release, rather than re-building the artifacts. Eliminates the risk of accidental master merges or commits resulting in untested code being released, and provides digest hash traceability for the history of artifacts.
12
12
* Enabling the decoupling of repository deployment and execution environment delivery based on the current git branch.
13
+
* Allowing for long-running non-release branches to be deployed to snapshots, automatically reversioning the artifacts based off the branch name.
13
14
* Automated deployment, promotion, and delivery of projects without the [maven-release-plugin](http://maven.apache.org/maven-release/maven-release-plugin/) or some other [*almost there* solution](https://axelfontaine.com/blog/final-nail.html).
14
15
* Customizing maven project and system properties based upon the current branch being built. This allows test cases to target different execution environments without changing the artifact results.
15
16
* Enabling automatic purging and resolving (force update) of 'release' and 'hotfix' release versioned dependencies resolved from the 'stage' repository.
@@ -24,6 +25,7 @@ This plugin solves a few specific issues common in consolidated Hudson/Jenkins C
24
25
4. Set arbitrary project properties based upon the type of GIT branch being built.
25
26
5. Reliably tag deploy builds from the master and support branches
26
27
6. Enable split 'deploy' vs. 'deliver' maven CI job configuration, without rebuilding artifacts for the 'deliver' phase.
28
+
7. Allow for deployment of long-running feature branches to repositories without having to mangle the version in the pom.xml.
27
29
28
30
In addition to supporting these goals for the project, this plugin does it in a manner that tries to be as effortless (yet configurable) as possible.
29
31
If you use non-standard gitflow branch names (emer instead of hotfix), this plugin supports that. If you don't want to do version enforcement, this plugin supports that.
@@ -107,14 +109,16 @@ All of the solutions to these issues are implemented independently in different
@@ -144,9 +147,9 @@ One common stumbling block for teams adjusting to gitflow with Maven projects is
144
147
In practice, the Maven versions should:
145
148
146
149
* Be synchronized with release branch and hotfix branch names.
147
-
* Never be -SNAPSHOT in the master, support, release, or hotfix branches. Also, no -SNAPSHOT parent or (plugin) dependencies are allowed. (This condition may be disabled by setting `enforceNonSnapshots` = `false`.)
148
-
* Always be -SNAPSHOT in the feature and develop branches.
149
-
* Be irrelevant if there's no git branch resolvable from your environment.
150
+
* Never be -SNAPSHOT in the master, support, release, or hotfix branches. Also, no -SNAPSHOT parent or (plugin) dependencies are allowed.
151
+
* Always be -SNAPSHOT in the develop branch.
152
+
* Be irrelevant if there's no git branch resolvable from your environment or working in a branch which is not deployed to remote repositories.
150
153
151
154
The `enforce-versions` goal asserts these semantics when it can resolve the `gitBranchExpression`.
152
155
@@ -166,9 +169,21 @@ The following properties change the behavior of this goal:
166
169
| supportBranchPattern | (origin/)?support/(.*) | No | Regex. When matches, signals a support branch (long term master-equivalent for older release) being built. Last subgroup, if present, must be start of the Maven project version. |
167
170
| releaseBranchPattern | (origin/)?release/(.*) | No | Regex. When matched, signals a release branch being built. Last subgroup, if present, must match the Maven project version. |
168
171
| hotfixBranchPattern | (origin/)?hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Last subgroup, if present, must match the Maven project version. |
169
-
| featureOrBugfixBranchPattern | (origin/)?(?:feature|bugfix)/(.*) | Yes | Regex. When matched, signals a feature or bugfix branch is being built. |
170
172
| developmentBranchPattern | (origin/)?develop | Yes | Regex. When matched, signals a development branch is being built. Note the lack of a subgroup. |
171
173
174
+
## Goal: `set-properties` (Dynamically Set Maven Project / System Properties)
175
+
176
+
Some situations with automated testing (and integration testing in particular) demand changing configuration properties
177
+
based upon the branch type being built. This is a common necessity when configuring automated DB refactorings as part of
178
+
a build, or needing to setup / configure datasources for automated tests to run against.
179
+
180
+
The `set-properties` goal allows for setting project (or system) properties, dynamically based on the detected git
181
+
branch being built. Properties can be specified as a Properties collection in plugin configuration, or can be loaded
182
+
from a property file during the build. Both property key names and property values will have placeholders resolved.
183
+
184
+
Multiple executions can be configured, and each execution can target different scopes (system or project), and can load
185
+
properties from files with an assigned keyPrefix, letting you name-space properties from execution ids.
186
+
172
187
173
188
## Goal: `retarget-deploy` (Branch Specific Deploy Targets & Staging)
174
189
@@ -185,11 +200,10 @@ plugins in the build process (deploy, site-deploy, etc.) will use the repositori
185
200
| Property | Default Value | Description |
186
201
| -------- | ------------- | ----------- |
187
202
| gitBranchExpression | current git branch resolved from SCM or ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
188
-
| deploySnapshotTypeBranches |`false`| When `true`, feature branches will also be deployed to the snapshots repository. |
189
203
| releaseDeploymentRepository | n/a | The repository to use for releases. (Builds with a GIT_BRANCH matching `masterBranchPattern` or `supportBranchPattern`) |
190
204
| stageDeploymentRepository | n/a | The repository to use for staging. (Builds with a GIT_BRANCH matching `releaseBranchPattern` or `hotfixBranchPattern`) |
191
205
| snapshotDeploymentRepository | n/a | The repository to use for snapshots. (Builds matching `developmentBranchPattern`) |
192
-
206
+
| otherDeploymentBranchPattern | n/a | Regex. When matched, the branch name is normalized and any artifacts produced by the build will include the normalized branch name and -SNAPSHOT. Deployment will target the snapshot repository |
193
207
194
208
**The repository properties should follow the following format**, `id::layout::url::uniqueVersion`.
195
209
@@ -238,20 +252,15 @@ Can be replaced with the following plugin configuration, which also introduces t
238
252
...
239
253
</build>
240
254
255
+
### Deploying non-release (OTHER) type branches as -SNAPSHOT releases.
241
256
242
-
## Goal: `set-properties` (Dynamically Set Maven Project / System Properties)
243
-
244
-
Some situations with automated testing (and integration testing in particular) demand changing configuration properties
245
-
based upon the branch type being built. This is a common necessity when configuring automated DB refactorings as part of
246
-
a build, or needing to setup / configure datasources for automated tests to run against.
247
-
248
-
The `set-properties` goal allows for setting project (or system) properties, dynamically based on the detected git
249
-
branch being built. Properties can be specified as a Properties collection in plugin configuration, or can be loaded
250
-
from a property file during the build. Both property key names and property values will have placeholders resolved.
251
-
252
-
Multiple executions can be configured, and each execution can target different scopes (system or project), and can load
253
-
properties from files with an assigned keyPrefix, letting you name-space properties from execution ids.
254
-
257
+
In addition to setting up repository targets for release branches, the `retarget-depoy` branch can deploy other branches
258
+
matching the `otherDeploymentBranchPattern` as -SNAPSHOT artifacts which include the branch name as build metadata.
259
+
This is loosely based on the [semVer](https://semver.org) semantic version scheme, in that the plugin will reversion any
260
+
artifacts to be produced with `+feature-branch-name-normalized-SNAPSHOT` where any characters not in `[0-9A-Za-z-.]` will
261
+
be replaced with `-`. Artifact versions for feature branches will _always_ be -SNAPSHOT, and will _always_ target the
262
+
Snapshots repository. The intent for this configuration setting is to provide a way for long-running branches (matching
263
+
a naming convention you define) can be published to a SNAPSHOT repo for use by other projects.
255
264
256
265
## Goal: `update-stage-dependencies` (Force update of dependency staged Releases)
257
266
@@ -339,8 +348,8 @@ The following table describes the git branch expression -> repository used for r
339
348
| supportBranchPattern | release |
340
349
| releaseBranchPattern | stage |
341
350
| hotfixBranchPattern | stage |
342
-
| featureOrBugfixBranchPattern | snapshots |
343
351
| developmentBranchPattern | snapshots |
352
+
| otherBranchesToDeploy | snapshots |
344
353
| All Others | local |
345
354
346
355
As an example, assume you have two CI jobs.
@@ -361,15 +370,40 @@ it's building. The attach-deploy will 'clean' the maven project, then download t
361
370
that the first build deployed into. Once they're attached to the project, the `jboss-as:deploy-only` goal will deliver
362
371
the artifacts built by the first job into a jboss application server.
363
372
373
+
# Additional Notes
374
+
## How Git branch name resolution works
375
+
1. If the `<scm>` sections of the pom points to a git repository, `git symbolic-ref HEAD` to is used to check the local branch name.
376
+
2. If the `symbolic-ref` fails then it's likely due to a detached HEAD.
377
+
This is typical of CI servers like Jenkins, where the commit hash that was just pushed is pulled.
378
+
This can also be done as a consequene of attempting to rebuild from a tag, without branching, or in some
379
+
workflows where code reviews are done without branches.
380
+
381
+
In the case of a detached HEAD the plugin will:
382
+
* Resolve the HEAD to a commit using `git rev-parse HEAD`.
383
+
*`git show-ref` to resolve which (local/remote) branches point to the commit.
384
+
* If the detached HEAD commit resolves to a single branch type, it uses that branch name.
385
+
3. If the first two methods fail, the plugin attempts to resolve `${env.GIT_BRANCH}`.
386
+
387
+
## To Debug the plugin (replicating a test-case but without being run from jUnit)
388
+
You can 'bootstrap' the plugin into your local repository and get the test project stubbed by running:
389
+
`mvn -Dmaven.test.skip=true install`
390
+
391
+
Then, change directories:
392
+
`cd target/test-classes/project-stub`
393
+
394
+
From there, you'll need to supply the required environment variables or commandline arguments to `mvnDebug`:
You can then connect a remote debugger and step through the plugin code.
364
400
365
-
# Resolving the Git branch name
366
-
As stated before, the plugin determines what to do by resolving the Git branch name.
401
+
## Building with IntelliJ IDEA notes
402
+
### To Debug Test Code:
403
+
Configure the Maven commandline to include
404
+
`-DforkMode=never` You will likely get warnings when you run maven with this argument.
367
405
368
-
* The first try is a `git symbolic-ref HEAD` to check the local branch name. If it's found, that's the branch name that's used.
369
-
* If the `symbolic-ref` fails then it's probably due to a detached HEAD. This typically happens on Jenkins, when it simply checks out the commit hash that was just pushed.
370
-
Or, it's because of a developer doing a `git checkout origin/feature/x`, e.g. when doing a code review and no local branch is required.
371
-
In such a case:
372
-
* The plugin will first resolve the HEAD to a commit using `git rev-parse HEAD`.
373
-
* Next, it will do a `git show-ref` to check which (local/remote) branches point to the commit.
374
-
* If it can resolve the commit to a single branch type (e.g. develop or master) then that's the branch name that's used.
375
-
* If all of the above fails, `${env.GIT_BRANCH}` is tried.
406
+
### To inspect code-coverage results from Integration Tests:
407
+
* Select the **Analyze** -> **Show Coverage Data** menu.
408
+
* In the dialog that appears, click the **+** in the upper left corner to `Add (Insert)`, and browse to `target/jacoco.exec`.
409
+
* Selecting that file will show coverage data in the code editor.
0 commit comments