Selenium With Jenkins- Continuous Integration and Deployment - selenium

I am new to Jenkins.
I have automation scripts designed in Selenium as Maven Project.
I am able to trigger the build (execute POM.XML from GIT repository) from Jenkins.
My current Flow is as below.
Eclipse -> GIT ->Jenkins (trigger POM.xml available in GIT).
This approach is only for the test team wherein the push the selenium code changes to GIT branch and the code is tested by executing the POM.xml file.
I want to include the Deployment step (for DEV team) in this cycle. So that the automation script executes on the latest deployment. So the flow should look something like below.
Eclipse (Dev code) -> GIT repo -> Jenkins (build) -> Jenkins (deployment in test environment) -> Jenkins (trigger POM.xml available in GIT)
This way I would be able to execute my POM.xml on every latest build.
Any help will be appreciated.

If you are a novice with Jenkins, start playing with it and download and install localy (https://jenkins.io/download/).
It is not that much to it. Here are a few simple steps.
install Jenkins, and probably have Maven, Java,
setup path in Jenkins to Maven and Java in Global Tool Configuration section ins Jenkins settings,
create a new Freestyle job,
connect to git to the desired project on git,
In section, build triggers add maven command like in console (without mvn) as "Invoke top-level Maven targets" with commands from maven like install, test etc.
Start job.
Hope this helps.

Jenkin has integration with Maven via Maven Plugin so
If you're using a freestyle project just add the relevant build step in Jenkins GUI
If you're using Jenkins Pipeline - declare your test execution via Pipeline Maven Plugin like:
node{
stage ('Automation') {
git url: 'https://path/to/your/test/repo'
withMaven(
maven: 'maven-3',
mavenSettingsConfig: 'my-maven-settings') {
sh "mvn clean test"
}
}
}
Be aware that Jenkins might not have GUI therefore you may need to either use headless browsers versions or install extra software to simulate display like Xvfb

Related

Should selenium tests be kept in separate project

I have a Java web app (Maven) where I have some Selenium tests.The testing framework is Junit 4.x.
I'm also using Jenkins for CI. Right now all my tests (integration + selenium) are kept under the src/test folder of the project.(classic maven structure)
Due to the fact that Jenkins cannot run selenium tests (it is not configured to do this - I'm running on a linux machine without a graphical interface and the solutions under this circumstances seems a little clumsily, but I was thinking to run a selenium server so that I can run all these tests on a windows slave machine ) I have to manually "remove from execution the selenium tests", otherwise I'll have a lot of failed tests.
What I want to accomplish is a scenario where:
1.Commit to SVN
2.Jenkins creates a build
3.Run the tests and if there is no problem here move to next step, otherwise,stop
4.Deploy the app to an app server
5.Run the selenium tests against that deployment as a post build script in Jenkins.
In order to have this running do I have to extract the selenium tests to other project ? (in order to avoid Jenkins running this tests along with the other integration/unit tests)
As you are using Maven and you say kept under the src/test folder of the project sounds just Perfecto.
You havn't mentioned in your question why Jenkins cannot run selenium tests (it is not configured to do this). As later in your question you have mentioned Run the tests, presumming you are using TestNG it's just one step configuration for Jenkins to execute pom.xml of Maven which will inturn call the *testng.xml as mentioned below :
Ensure your Automated Test Suite executes properly as TestNG Suite and Maven Test.
Start Jenkins and browse to Manage Jenkins -> Configure System
Scroll Down to JDK -> JDK installations and ensure JAVA_HOME is set to C:\path\to\jdk1.8.0_144. Uncheck Install automatically
Scroll Down further to Maven -> Maven installations and provide Name as MAVEN_HOME & MAVEN_HOME as C:\path\to\apache-maven-3.3.3. Uncheck Install automatically
Scroll Down to JDK -> JDK installations and ensure Local Maven Repository is set to Default(~/.m2/repository).
Apply & Save
On Jenkins Dashboard, Create a New Item as Maven project.
Scroll Down to Build section and provide Root POM as absolute path of the pom.xml e.g. C:\Users\<user_name>\LearnAutmation\maven.jenkins\pom.xml
Set Goals and options to clean install
The final step would be to move the testng.xml within \ProjectWorkSpace\src\main\resources\testng.xml and your pom.xml you have to mention the location of testng.xml as below :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Build your project through Jenkins
As per your specific question In order to have this running do I have to extract the selenium tests to other project ? the answer is No.
Solution :
If you want to execute both the Suites Integration and Selenium, this setup is yours.
If you want to execute either of the Suites seperately, divide the Integration and Selenium suites in different TestNG Groups and turn ON & OFF the execution of the TestNG Groups.

Deploy from maven released repository to application

I just figured out, how to release to CB hosted maven "release" repository. I am trying to figure out, how to deploy tagged version to CB application.
I understand, I can manually upload WAR file but is there any script. As far as I know maven plugin for CB doesn't support it.
I have one appserver is running snapshot builds from jenkins.
I have other appserver, which I want to deploy only tagged/released artifact.
There are four ways to deploy applications to the CloudBees RUN#cloud service:
Using the bees command provided by the SDK
Using the bees-maven-plugin
Using the manual upload via the web GUI
Using the CloudBees Deployer plugin for Jenkins
Which option you choose depends on where the deployment will take place from... And the from I am talking about is which machine is doing the deployment not where the file is sourced.
If running from a Jenkins job, the best bet is the Jenkins plugin.
If running from your own laptop, the web ui or the bees command is simplest.
If running as part of a maven build, the maven plugin is simplest... (Though I should warn that the maven plugin (temporarily removing my cloudbees hat and putting on my maven PMC hat) is shite and does it all arsewise ;-) )
Your best bet is to set up a Jenkins job that uses dependency:get to pull the artifact from the repo and then add a cloudbees deployer build step to push to RUN#cloud
The good news is that bashing the maven plugin into something more maven like is on our roadmap... Hopefully that will enable actions like you can achieve with the ship-maven-plugin#mojo where you can specify a specific released version for "shipping" to production.
I suppose, that what you want to do is to deploy a release artifact to your repository.
have a look at maven-release-plugin.
Briefly, what you need to do is:
$ mvn release:prepare
$ mvn release:perform
it's not so trivial, since you need to configure appropriately your pom.xml to get it working. Have a look at the maven-release-plugin examples and usage pages.
Are you creating the tag/release from a Jenkins build? If so you could probably use the Deploy to CloudBees post-build step with target/checkout/something.war.
More generally I guess you would want to write a script to use mvn dependency:get followed by the Bees SDK to obtain the latest released artifact and deploy it.

How to install a jar file from target to a specific location using maven?

Currently I have a simple maven project that is building a jar file and putting it inside target/some-1.0.jar when i run mvn install.
I want to copy this file to another location when I run mvn deploy.
Currently the location is on the same machine, but it would also be great if the solution could be applied for multiple targets, some of them being on other machines (scp deployment).
What is the easiest solution to do this? I would be nice, if you could include an example too.
Details: I have few jira plugins that are compiled as jar files and I just want to be able to run a single maven command that would copy the files to the server and eventually restart the server.
mvn deploy is intended for deployment to a remote Maven repository. mvn install is used for copying to the local Maven repo (so actually, the jar is also ending up in $HOME/.m2/repository, as well as target).
I'm not sure what you're intending to do, but I suggest you look at deploying something like http://www.sonatype.org/nexus/ if you want Maven artifacts to be available to multiple machines. This will integrate nicely with the rest of Maven.
Edit: based on your updated question, it's probably best to investigate the Wagon ssh plugin, or see if there's an Ant plugin. A suitable phase would be pre-integration-test: install and deploy should be run after you've run your integration tests to check the artefact works as expected. Use profiles to distinguish the local vs. remote cases.

Make hudson automatically show pom description in its project page

I use Hudson to do continuous integration on some maven projects. For these projects, I would like to have the pom description used as content for the Hudson job description. is there a solution to automatically have this configured ?
That's a bit hard to do because Hudson needs the config so it can checkout the POM. What you can try is use the command line API to configure the project.
Another solution is to run mvn install site. That will generate the web site for the project and Hudson will present a link to it right below the description, so you can use this description:
This is a Maven project; click the link below to visit the web site.
You can just run mvn site no mvn install needed to see the link about the generated site in Hudson.

Hudson can't build my Maven 2 project because it says artifacts are missing from the repository? (they aren't)

I'm using Hudson and Maven 2 for my automated build/CI. I can build fine with maven from the command line, but when I run the same goal with Hudson, the build fails complaining of missing artifacts. I'm running Hudson as a windows XP service.
Obvious question, but have you got Hudson set up to point to the same Maven repository as your command line build? You can check this from the Hudson admin gui - look in the Maven section of the Manage Hudson page. This should have a MAVEN_HOME environment variable listed. Look in the settings.xml file under:
MAVEN_HOME\conf\settings.xml
The localRepository configuration item is the location of the Maven repository that the Hudson build is using.
Make sure you're running Hudson as the same user that you are using to run Maven from the command line. Maven creates a separate repository for each user. If you are running Hudson as a Windows service, this won't be the same user as you have logged on as and will be running "mvn" commands with. This means the artifacts in the repositories may be different.
To fix, either start Hudson manually as the user which works, or update the repository for the user which Hudson is running as.