how to automatically set scm connection in maven pom? - maven

We are trying to run release:prepare but this produces error like below.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:
prepare (default-cli) on project test-module:
Missing required setting:
scm connection or developerConnection must be specified. -> [Help 1]
We want to avoid setting the scm.connection manually.
How to set scm.connection automatically to the current URL? - For SVN and git.
The information must be somewhere within the (metadata of the) module, since svn info displays the value under URL.

In principle, you should be able to set the developerConnection by using a parameter, but (thanks to khmarbaise for telling me) there is a bug (https://issues.apache.org/jira/browse/MRELEASE-1017) so that this does not work at the moment.
I currently work around this with my own Maven plugin. It compares the connection and developerConnection entries of the pom with the url provided by the build server (the build server knows the url because it checked out the code) and adjusts the urls if necessary (followed by scm:checkin).

Related

maven release without scm/vcs

I want to build a release version of my spring application with maven without the use of scm or ANY OTHER version control system - All I want is to build an application ready to be served via tomcat. While this sounds simple, it seems impossible for me to achieve.
I already tried options like suppressCommitBeforeTag / remoteTagging / pushChanges / dryRun directly via the command line
mvn -DremoteTagging=false -DsuppressCommitBeforeTag=true -DpushChanges=false release:prepare or by setting inside the pom.xml in the corresponding plugin configuration.
No matter what I do, I always get
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-release-plugin:3.0.0-M1:prepare
(default-cli) on project eStore: Missing required setting: scm
connection or developerConnection must be specified.
How can I completely deactivate version control / remote tagging when releasing?

Why add a distribution management in POM if Jenkins already knows about it

Pretty much what the title say.
I am trying to build a CI/CD for WSO2. While following this tutorial:
https://docs.wso2.com/display/IntegrationCloud/Implement+Continuous+Integration+and+Deployment+with+Jenkins
It don't say anything about adding a DistributionManagement on the POM and it even has a special POM configuration section, but nevertheless, jenkins is throwing a
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project HelloWorld: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
So, if jenkins already has the repo URL, the branch and the github, and the POM has a deploy goal that should deploy to a URL:
1) why do I need the Distribution Management?
2) Can I point it to any location like my file system or do I have to point it to the cloud I actually want to deploy to?
according to maven documentation you can upload your build artifact directly to a server with maven using the tag distributionManagement
https://maven.apache.org/pom.html
the important part is the url tag. you can use scp or sftp (maybe other protocols)
scp://user:password#serverUrl/var/some/directory
I would recommend to test locally the command deploy and when you are sure it works, use jenkins.
If you want to make a state of the art jenkins job, I would recommend to use jenkins pipeline, execute maven with sh command and publish to a server using ssh steps provided by ssh-steps-plugin

scm connection vs developerConnection

Can anyone tell me the difference between scm connection and developerConnection in maven?
I am trying to build using mvn release:prepare and it requires either one of them.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare
(default-cli) on project was-topology-legacy-dsl: Missing required
setting: scm connection or developerConnection must be specified. ->
[Help 1]
As mentioned in POM Reference: SCM The connection requires read access for Maven to be able to find the source code (for example, an update), developerConnection requires a connection that will give write access. It is an information for our project where the other, including with another maven plugin to re-use this information further. In this case the Maven Release Plugin.
The Maven Release Plugin: Prepare a Release also provides us the behind the scenes what it does for us during the release:prepare. There are some significant steps which requires the access to the scm as the following: -
Transform the SCM information in the POM to include the final destination of the tag
Tag the code in the SCM with a version name (this will be prompted for)
Commit the modified POMs
This means we should provide the scm information when using the maven release plugin. Especially the developerConnection. If we don't provide, the plugin is not able to execute.
Another useful information is Maven Release Plugin: Perform a Release and Maven Release Plugin: Rollback a Release.

Maven release without tagging

The main idea of the question is: is that a way to specify that maven release should skip tagging when performing a release?
I have the following context: we have a TFS (Team Fundation Server) as a system that version our software. We also use a svn bridge that "talks" with the TFS and developers and CI tools use it. When performing a mvn release:clean release:prepare release:perform maven complains that it cannot find or create a tag (somehow translating the tag command of the svn into a similiar command in tfs crashes). Any suggestions are appreciated.
The error looks like this:
28-May-2013 15:51:04 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.1:branch (default-cli) on project spring-hibernate-mysql: The scm url is invalid.
28-May-2013 15:51:04 [ERROR] - scm:svn:https://${TFS_SERVER}:${PORT}/${PATH_TO_APP}/tags/dbDiagnostic-1.0.0-RELEASE url isn't a valid svn URL.
28-May-2013 15:51:04 [ERROR] -> [Help 1]
I mention that the url is ok, because the step before this, in a CI plan is a "checkout sources" step with the same url.
The maven release plugin depends on the svn tag as it checks out the tagged version during the release process. So the answer is: No, there is no way to release without a tag.
The svn URL above is not valid, you should consider fixing it by resolving the variable substitutions.
To your question:
You can disable remote tagging by setting the remoteTagging property to false as described in: http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#remoteTagging
Note that in only works with SVN.
However, the reason for this error is most likely because maven failed to create the tag in the previous step, due to e.g. authentication failure or incorrect URL configuration ( see "tag base" attribute & etc ).

Passing scm tag values through a parameter by jenkins

Can I pass the values ​​of the parameter of scm for Jenkins?
in my pom.xml, I have the values ​​set as default:
<scm>
<connection> scm:svn:https://172.10.10.30/svn/repPortal/branches/2012/Branch_A/ </ connection>
<developerConnection>scm:svn:https://172.10.10.30/svn/repPortal/branches/2012/Branch_A/</developerConnection>
</ scm>
The problem is when I running with another branch and want to run a release by jenkins (within the release process, it generate the tag of the project) it always will get the value that is defined in pom.
I would passing a new path in a especific parameter at Jenkins that automatically will be set in scm pom project.
I did some tests by setting a string parameter in a parameterized building but he did not recognize the given parameters and error in construction.
Another way was to pass through the "release goals and options":
-X -Dresume=false release:clean release:prepare release:perform \
-DscmConnection="scm:svn:https://172.10.10.30/svn/repPortal/branches/2012/Branch_B"-DscmDeveloperConnection = "scm: svn: https :/ / 172.10.10.30/svn/repPortal/branches/2012/Branch_B "scm: validate
The error persisted ...
Caused by: org.apache.maven.shared.release.ReleaseFailureException:
Missing required setting: scm connection or developerConnection must be specified.
Is there a way to do this so that I can tell by Jenkins?
I noticed the properties defined for the SCM connections are not correct. The property for setting the SCM connection on the command line is -Dproject.scm.connection and developer connection is -Dproject.scm.developerConnection.
According to MRELEASE-707 the properties connection and developerConnection are read only and cannot be set directly. You have to define your own property for the url and use it as placeholder (see: How to override maven property in command line?).

Resources