Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

04 October, 2015

[ERROR] Unknown lifecycle phase "mvn"


[ERROR] Unknown lifecycle phase "mvn" You must specify a valid lifecycle phase or a goal in the format.

This Jenkins issue is very common, while configuring the maven job in jenkins. One of my peer faced this issue during her development. Then we investigate and fixed this issue.


Jenkins Configuration :-




Error Log :-

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.316 s
[INFO] Finished at: 2015-10-05T15:10:46+11:00
[INFO] Final Memory: 20M/491M
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
[JENKINS] Archiving /opt/jenkins_dev/workspace/MYAPP_BIZ/pom.xml to au.com.mycompany.group.lar.testing.biz/Myapp/0.0.1-SNAPSHOT/Myapp-0.0.1-SNAPSHOT.pom
channel stopped
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE


Solution :-

Its a simple mistake, that while configuring the jenkins jobs maven goal, we are simple trying with mvn clean install  , which is a against maven life cycle policy.

So , we fixed this by removing the mvn  . Correct command is clean install. Then it worked.




Hope it will help you. Happy Building.

Follow for more details on Google+ and @Facebook!!!



Find More Solutions -


24 March, 2015

How to skip integration test in maven build ?

Its not so easy when I was trying with all the possible and lost my 3 hours of valuable time. Its really very pathetic when you are trying to do something and its not happening within your time period....

This happens me when I was trying to build without the integration tests only. My scenario was to skip only integration tests ,but it must execute the unit test cases. I gooooogle almost many links but no luck , but finally the luck clicks and it works for me with below pom.xml configuration.


Add the below tag into you pom.xml


<build>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>



Here you can use <exclude> tag and mentioned any test class you want to skip.If your java class name contains *ITest.java (i.e. MyMethodITest.java)

<exclude>**/*IT*.java</exclude>

or 

<exclude>**/*AnyTestClasses.java</exclude>



Not only integration test you can skip any classes over here, but you need to configure the pom.xml properly.And in the maven command you can use below command as normal (i.e. mvn clean install)


Note - Be careful about the version, because it may not work for all version.

I hope it will help you all.



20 December, 2014

How to skip test case in Maven build ?

You can skip the test in two following ways :-

By configuring the Pom.xml , if you are using surefire plugin then you can configure as below. 


<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>

  </build>

For specific module test you can create profile in pom.xml for specific environment and it will help to skip the test cases.You can skip this specified profile "noTest".


<profiles>
    <profile>
      <id>noTest</id>
      <activation>
        <property>
          <name>noTest</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.2</version>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>


By using Command Line :- 


1) -Dmaven.test.skip=true

2) -DskipTests ( The values can be true/false) 

Example - 


1 ) mvn clean install -DskipTests=true

2 ) mvn clean install -Dmaven.test.skip=true

 

Hope it will help you.

Follow for more details on Google+ and @Facebook!!!


Find More Solutions -

How to create maven job in Jenkins



As we know Jenkins is a tool  , and its used for build and release any project.There are many such tools are available i.e. Hudson.  For creating job/project on Jenkins below steps/screen shots need to follow.

Step 1 - Login & Dashboard

Login to Jenkins with valid credential and you are in Dashboard.



Step 2 - Create Job

Click New Item (left side menu) to create a new Job/Project . Provide the Job Name as per your project requirement. Here this example my job name is "HelloWorld_Job".




Here in the above image many options are available for creating many kind of job. Also you can copy any existing job instead of creating a new. You can select Copy Existing Items and provide the existing job name inside the text box.



Step 3 - Job Configuration


There are few certain configuration is required for this job execution. For building any job we need few configuration and commands as below.





You need to configure the source code location from which you are going to build.In the below image I have used "Git" as source code management tool. You can use any source code management tool like SVN, CVS ,etc. And the important part of this configuration is the location of your project . So, make your the location you have provided is correct and relevant.



Then  there are few more setup is required make this job elegant and accurate. But these options/settings are fully optional. Read all the settings carefully and configure as per you needs.Some useful configurations as below.




As the part of configuration the major part is maven command for execute the build. The screen shot below shows the configuration about maven command for goal. This project is a maven project and we need maven command for build this job/project. 




Common maven commands which is used for a clean build is "mvn clean install". Also there are many other additional commands which will help you to achieve your goal.Read more here about Maven.


Step 4 - Start Build 


The final step is to start the build. Once all the above steps are completed and you are ensure about the configuration , then you can do the build . The build execution will provide you the artifacts i.e. jar ,war,ear, etc.




 If the job execution is success, the you can go for deployment. Now you are done with this job...


Enjoy the Build and Release process.






Hope it will help you. Happy Building.

Follow for more details on Google+ and @Facebook!!!


Find More Solutions -

17 December, 2014

Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref



This issue occurs when I tried with Jenkins build using Maven Release Plugin. I was trying to build my production release artifacts. I was building my "master" branch and its for final release. I have used Git as repository. I faced this issue when clicked on "maven release build" link on left side corner of my Maven project (Jenkins job) .


As we know build issue is common for developers those are actively participating with Build and Release. This issue over Jenkins is common , but I never found any direct or easy solution for this. I spend couple of hour to resolve and goooogle almost all relavant sites and article.But, not able to work out. Finally did it by some HIT and TRY ,then it works for me.   


Issue log details :-

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.884s
[INFO] Finished at: Wed Dec 17 18:05:43 EST 2014
[INFO] Final Memory: 15M/301M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0:prepare (default-cli) on project hello_world_app: An error is occurred in the checkin process: Exception while executing SCM command. Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[JENKINS] Archiving /opt/jenkins_dev/workspace/SDP_BIZ_HELLO_WORLD_APP/pom.xml to in.com.company.xcop.sdp.bizservice.test.dao/hello_world_app/0.0.8-SNAPSHOT/ hello_world_app -0.0.8-SNAPSHOT.pom
channel stopped
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds



Solution :-

 In Jenkins job , open the configuration and go to Git configuration => Advance Options => << add your local branch name >>. In my case I have added "master" .

If you are using some other version of jerkins then , you may find the similar settings with other way. In the same way Git configuration => Advance Options => Additional Behaviors => Check out to specific local branch => << Add your local branch name >>.   

Attached the screenshot below with highlight. 







Hope it will help you. Happy Building.