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
Copy file name to clipboardExpand all lines: README.md
+25-29Lines changed: 25 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,11 @@ It does so by:
7
7
* Enforcing [gitflow](http://nvie.com/posts/a-successful-git-branching-model/) version heuristics in [Maven](http://maven.apache.org/) projects.
8
8
* Coercing Maven to gracefully support the gitflow workflow without imposing complex CI job configurations or complex Maven setups.
9
9
* Setting distributionManagement repositories (for things like [maven-deploy-plugin](https://maven.apache.org/plugins/maven-deploy-plugin/)) based upon the current git branch.
10
-
* SCM tagging builds for the master branch, using the CI server's repository connection information. (Zero Maven scm configuration necessary)
10
+
* SCM tagging builds for the master branch. 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
13
* 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
+
* 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.
14
15
15
16
# Why would I want to use this?
16
17
@@ -32,11 +33,16 @@ All of the solutions to these issues are implemented independently in different
32
33
33
34
# I want all of that. (Usage)
34
35
35
-
1. Make sure your build server sets environment variables for git branches and git URLs. The plugin defaults are configured out of the box for Jenkins & Hudson.
36
-
2. Configure the plugin goals and add the build extension to your Maven project. Here's an example that will get you going quickly...
36
+
1. Make sure you have a your Project SCM configured for your git repository, or that your build server sets environment variables for git branches and git URLs.
37
+
Out of the box, the plugin will try to resolve the git branch based upon the SCM definition on your maven project, or fall back to the environment variables set by Jenkins and Hudson.
38
+
2. Configure the plugin goals and add the build extension to your Maven project. Here's an example that will get you going quickly with all the features...
<!-- The plugin will read the git branch ang git url by resolving these properties at run-time -->
56
-
<gitBranchProperty>
57
61
</configuration>
58
62
<executions>
59
63
<execution>
@@ -89,24 +93,24 @@ In practice, the Maven versions should:
89
93
90
94
* Be synchronized with release branch and hotfix branch names.
91
95
* Never be -SNAPSHOT in the master branch, release, or hotfix branches.
92
-
* Always be -SNAPSHOT in the development branch.
96
+
* Always be -SNAPSHOT in the develop branch.
93
97
* Be irrelevant if there's no git branch resolvable from your environment.
94
98
95
99
The `enforce-versions` goal asserts these semantics when it can resolve the `gitBranchExpression`.
96
100
97
101
The goal accomplishes this by checking the Maven pom.xml version value, and asserting the -SNAPSHOT status, as well as matching the current branch name
98
-
against regular expressions, extracting version numbers from the branch names where applicable. If a regex specifies a subgroup 1, the content of that
99
-
subgroup is asserted to equal the version defined in the pom.xml.
102
+
against regular expressions, extracting version numbers from the branch names where applicable. If a regex specifies subgroups, the content of the
103
+
last subgroup is asserted to equal the version defined in the pom.xml.
100
104
101
105
The following properties change the behavior of this goal:
| gitBranchExpression | ${env.GIT_BRANCH} | n/a | Maven property expression to resolve in order to determine the current git branch |
106
-
| masterBranchPattern | origin/master | No | Regex. When matched, signals the master branch is being built. Note the lack of a subgroup. |
107
-
| releaseBranchPattern | origin/release/(.*) | No | Regex. When matched, signals a release branch being built. Subgroup 1, if present, must match the Maven project version. |
108
-
| hotfixBranchPattern | origin/hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Subgroup 1, if present, must match the Maven project version. |
109
-
| developmentBranchPattern | origin/development| Yes | Regex. When matched, signals a development branch is being built. Note the lack of a subgroup. |
109
+
| gitBranchExpression |current git branch resolved from SCM or ${env.GIT_BRANCH} | n/a | Maven property expression to resolve in order to determine the current git branch |
110
+
| masterBranchPattern |(origin/)?master | No | Regex. When matched, signals the master branch is being built. |
111
+
| releaseBranchPattern |(origin/)?release/(.*) | No | Regex. When matched, signals a release branch being built. Last subgroup, if present, must match the Maven project version. |
112
+
| hotfixBranchPattern |(origin/)?hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Last subgroup, if present, must match the Maven project version. |
113
+
| developmentBranchPattern |(origin/)?develop| Yes | Regex. When matched, signals a development branch is being built. Note the lack of a subgroup. |
110
114
111
115
## Goal: `retarget-deploy` (Branch Specific Deploy Targets & Staging)
112
116
@@ -122,7 +126,7 @@ plugins in the build process (deploy, site-deploy, etc.) will use the repositori
122
126
123
127
| Property | Default Value | Description |
124
128
| -------- | ------------- | ----------- |
125
-
| gitBranchExpression | ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
129
+
| gitBranchExpression |current git branch resolved from SCM or ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
126
130
| releaseDeploymentRepository | n/a | The repository to use for releases. (Builds with a GIT_BRANCH matching `masterBranchPattern`) |
127
131
| stageDeploymentRepository | n/a | The repository to use for staging. (Builds with a GIT_BRANCH matching `releaseBranchPattern` or `hotfixBranchPattern`|
128
132
| snapshotDeploymentRepository | n/a | The repository to use for snapshots. (Builds matching `developmentBranchPattern`|
@@ -179,26 +183,18 @@ Can be replaced with the following plugin configuration, which also introduces t
179
183
In a gitflow environment, a commit to a master branch should trigger a job to build on the master branch, which would result in the release being tagged if successful.
180
184
181
185
The `tag-master` goal executes the [maven-scm-plugin tag goal](https://maven.apache.org/scm/maven-scm-plugin/tag-mojo.html) when the
182
-
`gitBranchExpression` resolves to a value matching the `masterBranchPattern` regular expression. To determine the SCM URL to use, the `gitURLExpression`
183
-
is evaluated at run-time. The default expression, `${env.GIT_URL}`, is provided by Jenkins & Hudson.
184
-
185
-
To resolve the `<developerConnection>` in an `<scm>` block in your pom, you can specify the following in your plugin configuration:
`gitBranchExpression` resolves to a value matching the `masterBranchPattern` regular expression. To determine the SCM URL to use, the plugin looks for a
187
+
`developerConnection` or `connection` information in an SCM block, and if not found the `gitURLExpression` is evaluated at run-time.
188
+
The default expression, `${env.GIT_URL}`, is one that is commonly provided by Jenkins & Hudson.
190
189
191
190
The following properties can be configured for this goal:
| gitBranchExpression | ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
196
-
| gitURLExpression | ${env.GIT_URL} | Maven property expression to resolve for the GIT URL connection to use. |
197
-
| masterBranchPattern | origin/master | Regex. When matched against the resolved value of `gitBranchExpression` this plugin executes the scm:tag goal using the `gitURLExpression` to resolve the git URL to use. |
194
+
| gitBranchExpression |current git branch resolved from SCM or ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
195
+
| gitURLExpression |current git branch resolved from SCM or ${env.GIT_URL} | Maven property expression to resolve for the GIT URL connection to use. |
196
+
| masterBranchPattern |(origin/)?master | Regex. When matched against the resolved value of `gitBranchExpression` this plugin executes the scm:tag goal using the `gitURLExpression` to resolve the git URL to use. |
198
197
| tag | ${project.version} | An expression to use for the SCM tag. |
199
-
| tag.plugin.groupId | org.apache.maven.plugins | The groupId of the plugin to use for tagging. |
200
-
| tag.plugin.artifactId | maven-scm-plugin | The artifactId of the plugin to use for tagging. |
201
-
| tag.plugin.version | 1.9.4 | The version of the plugin to use for tagging. |
202
198
203
199
204
200
## Goal: `promote-master` and the Build Extension. (Copy Staged Artifacts to Releases)
@@ -271,7 +267,7 @@ that the first build deployed into. Once they're attached to the project, the `j
271
267
the artifacts built by the first job into a jboss application server.
272
268
273
269
274
-
## Goal: `set-properties` (Dynamically Set a Maven Project / System Properties)
270
+
## Goal: `set-properties` (Dynamically Set Maven Project / System Properties)
275
271
276
272
Some situations with automated testing (and integration testing in particular) demand changing configuration properties
277
273
based upon the branch type being built. This is a common necessity when configuring automated DB refactorings as part of
Copy file name to clipboardExpand all lines: src/main/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsMojo.java
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -28,13 +28,15 @@ protected void execute(final GitBranchType type, final String gitBranch, final S
28
28
thrownewMojoFailureException("The current git branch: [" + gitBranch + "] is defined as a release branch. The maven project version: [" + project.getVersion() + "] is currently a snapshot version.");
29
29
}
30
30
31
-
// If there is a group 1, expect it to match (exactly) the current projectVersion.
32
-
if (gitMatcher.groupCount() >= 1) {
33
-
if (!gitMatcher.group(1).trim().equals(project.getVersion().trim())) {
34
-
thrownewMojoFailureException("The current git branch: [" + gitBranch + "] expected the maven project version to be: [" + gitMatcher.group(1).trim() + "], but the maven project version is: [" + project.getVersion() + "]");
31
+
// Expect the last group on non-master branches to match (exactly) the current projectVersion. (only release / hotfix branches)
32
+
if (gitMatcher.groupCount() >0 && !GitBranchType.MASTER.equals(type)) {
33
+
if (!gitMatcher.group(gitMatcher.groupCount()).trim().equals(project.getVersion().trim())) {
34
+
thrownewMojoFailureException("The current git branch: [" + gitBranch + "] expected the maven project version to be: [" + gitMatcher.group(gitMatcher.groupCount()).trim() + "], but the maven project version is: [" + project.getVersion() + "]");
thrownewMojoFailureException("The current git branch: [" + gitBranch + "] is detected as the gitflow development branch, and expects a maven project version ending with -SNAPSHOT. The maven project version found was: [" + project.getVersion() + "]");
0 commit comments