Continuous Integration with Talend and Jenkins/Maven - maven

I have a Talend studio Enterprise veresion 6.4.1. I have downloaded the CI builder and installed with maven using the below command.
mvn install:install-file -Dfile=ci.builder-6.4.1.jar -DpomFile=ci.builder-6.4.1.pom
I have exported the job from Talend studio put into the Git. It contains the following files.
1) process a) .items b) .properties c).screenshot
2) talend.project
I have created a pom.xml with the below details
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.talend</groupId>
<artifactId>buildsources</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.talend</groupId>
<artifactId>ci.builder</artifactId>
<version>6.4.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I have placed pom.xml in the root folder of commandline workspace.
I placed the checked out folder inside command line workspace .
After that I executed the commandline.bat inside Talend studio to start the Talend.
I tried executing the below command to generate the source file.
mvn org.talend:ci.builder:6.4.1:generate -X -Dcommandline.workspace="D:\ci-builder\commandline_workspace\TEST" -Dcommandline.host=localhost -Dcommandline.port=8002 -Dcommandline.user=dummy#talend.com -DprojectsTargetDirectory=D:\buildsources\
Now it is able to find the project but at the end it says no job
[INFO] Preparing for the project: TEST
[INFO] Logon project
[INFO] Generating sources...
[INFO] Logoff project
[WARNING] There's no job in current project!
I am using Windows machine to test this - Windows 10 64 bit.
Maven version is 3.5.3
I have been referred the below links for doing this.
https://community.talend.com/t5/Architecture-Best-Practices-and/Continuous-Integration-with-Talend-CI-Builder-6-3/ta-p/33033
https://akhileshthipparthi.wordpress.com/2017/01/23/talend-ci-using-jenkins/
But when I check the .Java folder in my Talend installation directory command line workspace, I can see some files generated. pom.xml and pom_routines.xml. But there are no job related files getting generated.
And with those pom.xml , if I do a mvn clean install, it is generating a routines.jar file only in the target directory.
I am not able to proceed further.
Any pointers will be helpful.

One thing I wanted to highlight is that, for talend CI builder to work there is no need to writing test cases.
I was able to build the job using the CI builder using the below steps.
Inside the command line work space, you need to keep the complete project structure.
Checkout the source files from Git and copy the files to the project folder.
All the source files will be present inside the process folder of the project folder.
Setup the maven repository for Talend command line. It will be inside the configuration folder inside the Talend folder.
Execute the below command to Generate the source code inside the command line workspace.
Here SayHello is the Job name.
mvn org.talend:ci.builder:6.4.1:generate -Dcommandline.workspace="D:\ci-builder\commandline_workspace\" -Dcommandline.host=localhost -Dcommandline.port=8002 -Dcommandline.user=dummy#talend.com -DprojectsTargetDirectory=D:\ci-builder\target -DitemFilter=(type=process)and(label%SayHello*)
if there is a parent child job, we need to place all the jobs inside a folder and we need to refer that path during generate source.
Here Sample is the folder name
mvn org.talend:ci.builder:6.4.1:generate -Dcommandline.workspace="D:\ci-builder\commandline_workspace\" -Dcommandline.host=localhost -Dcommandline.port=8002 -Dcommandline.user=dummy#talend.com -DprojectsTargetDirectory=D:\ci-builder\target -DitemFilter=(type=process)and(Path%Sample*)
It will generate the source files and it will be kept in "D:\ci-builder\target"
Now navigate to that path and do mvn clean package
The job will be built and it will be placed inside the target folder. It will contain all the related Jar's, shell script, batch script and libraries and routines. Also it will have the entire folder structure.
Note : If you get the message like, there is no job in folder, just check if there is any error in the talend command line shell. Mostly u can encounter, the .Java folder is missing in command line workspace or there will be dependency errors (missing Jars in the maven local repo).

As mentioned in the prerequisites section of the Talend documentation you linked, your jobs must have a test case
Talend Jobs
Jobs containing test cases for Continuous Testing
Otherwise they won't be detected.
Please create a test case for your job, and try again.

Related

IntelliJ IDEA - Run/debug doesn't copy resources

I have a maven project which is packaged as WAR. The POM looks something like the following:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<artifactId>my_app</artifactId>
<packaging>war</packaging>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
...
</plugin>
...
</plugins>
</build>
</project>
When I manually run the command mvn package, a WAR is generated with directory target/my_app where my web resources (JSP, CSS, JS, images, etc.) are copied to. The generated WAR, if uploaded to an Application Server, works fine.
However, if I use IntelliJ IDEA's Run/Debug configuration (which is configured to deploy the WAR to an Application Server (JBoss if that matters)) to do the same, I don't see the web resources. Only configuration XMLs and compiled classes is present in the target/my_app directory. The applicaiton server starts up all fine without any errors and WAR is deployed successfully, however I can't accesss it as it returns 404.
How can I acheive what I get when building and manually uploading the WAR using Run/Debug of IntelliJ IDEA?
UPDATE:
Before launch tasks are:
Build
Build 'my_app:war exploded' artifact
I had the same issue after installing 2018.1 IntelliJ IDEA. Reverting back to version 2017.3 solved the problem. It looks this is a bug with the new version since I had the same settings for both. Hope this helped.
I had similar issue in which when I was running from the command line then it was copying all the resources (example JSP etc.) but Intellij was not copying it.
As part of workaround I added the goal of 'war:exploded' along with 'compile' then it resolved my issue.
So in Maven config command line parameters will be (may differ for you):
clean compile war:exploded
Screenshot for reference.

How to make a WAR file from angular 2 (angular-cli) project?

I want to make a war file to deploy the angular2 project in an apache tomcat server. I made a maven project and inserted the angular2 project inside it. Then I made the webapp folder(instead of the dist folder in the angular2 project) in the src/main in the maven project using angular-cli. When I run the apache server it shows the following errors.
Error loading http://localhost:8080/vendor/angularfire2/angularfire2.js as "angularfire2" from http://localhost:8080/app/app.module.js ; Zone: ; Task: Promise.then ; Value: Error: Error: XHR error (404 Not Found) loading http://localhost:8080/traceur(…) null
This looks like the troublesome dependency is the angularfire2. How to figure this our? Btw, I use angular2 rc-5.
I wanted to post a complete answer to this question since there are lots of views to this question.
The answer works for all angular 2+ versions.
The procedure is as follows.
First you need to create a POM file in your project's root directory. Include the following code into the POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd http://maven.apache.org/POM/4.0.0 ">
<modelVersion>4.0.0</modelVersion>
<groupId>it.your-company</groupId>
<artifactId>your-project-artifact-id</artifactId>
<version>1.0.0</version>
<name>your-project-name</name>
<description>Any description</description>
<packaging>war</packaging>
<build>
<finalName>target-file-name</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>dist</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/${project.build.finalName}</path>
<update>true</update>
<url>http://localhost:8080/manager/text</url>
<username>tomcat</username>
<password>tomcat321</password>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here, I have included the maven war plugin to build the war file as well as the maven tomcat plugin to run the war using IntelliJ idea.
Then you need to change the base URL of your index.html file as base href="/target-file-name".
If you are running the war using maven tomcat plugin, the URL for your app would be http://localhost:8080/target-file-name
Now build your angular project using ng build --prod. This will create all the required deployment files (build files) in the dist folder.
Now run mvn clean package to package your build files to a war file. The war file will be created inside the target folder from your root directory of your project.
(Optional) You may also run the war file using maven tomcat plugin too.
If you want to deploy locally. Say specifically at localhost:8080(Tomcat) , go to the service.msc and start tomcat Services. Build your angular 2 /angular 4 using (ng build). Now open the angular project folder and copy the files inside the dist folder to a new folder say(webui). Open index.html page and give as . Copy this folder to "C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps". Go to browser and type localhost:8080/webui.
This is how i deployed my angular 4 static content in tomcat.
Hope this helps you.
In your index.html set base href to "" or in your case (tomcat) to "webapps" that works for me

Extract current folder name within maven pom.xml file

I am looking for a way to dynamically extract the current folder name within maven pom.xml file.
For Example:
if the pom.xml file is at /home/jenkins/workspace/bdms-ci/bdms-bcr/pom.xml
then bdms-bcr is the current folder.
See a code snippet:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<testClassesDirectory>../../bdms-ci-improve/${project.basedir}/target/test-classes</testClassesDirectory>
<classesDirectory>../../bdms-ci-improve/${project.basedir}/target/classes</classesDirectory>
</configuration>
</plugin>
${project.basedir} will bring the full path which is not good since only the current folder is needed.
I tried to work with MavenProject class from the maven api document:
${project.file.parentFile.name} or ${project.file.name}, but it didn't work.
remember it is maven multi project and everything has to be dynamically.
The whole issue is for jenkins ci build which use parallel-test-executor plugin. I would like to compile once in the main job and then all the other test execute jobs will will only test by looking into the compiled code.
Using maven 3.2.3
#guymi,
Seems like you should be able to simply use ${project.artifactId} or perhaps ${parent.artifactId}.
EDIT
Or does your artifactId name disagree with the directory it's stored in?
If so, that's possible but not good practice and should be avoided.
It is not possible to do it. simple as that.
A workaround solution is by using artifactId with the same name as folder name. then you can do:
../../bdms-ci-improve/${project.artifactId}/target/test-classes</testClassesDirectory>

Maven: How to confine the application output to the target directory

I have a java application that uses maven for build management.
When I run the generated application jar with
java -jar myjar
the output files generated by the application end up in the projects root directory. So if I execute the jar in /my/project/dir and create a filewriter to write to logs/mylog
The resulting file ends up in
/my/project/dir/logs/mylog
Exactly as expected.
HOWEVER:
When maven surefire plugin executes the unit tests, the files end up in the module directory.
Say that i compile a maven project in /my/module.
The compiled files end up in /my/module/target/classes.
When maven executes these classes, through unit tests, the output of the same classes ends up in
/my/module/logs/mylog
I would like the files to end up in the target dir like
/my/module/target/logs/mylog
As this is where the class files reside.
So I am looking for a way to configure maven surefire to define the java classes' root directory to point to target instead of the module dir.
EDIT:
I have found this post:
Maven: change the directory in which tests are executed
That seems to attempt a fix to my problem. However, if i set the workingdirectory to my target dir, the tests can no longer find my resources, even if they are copied from the modules ${basedir} to ${basedir}/target
You should set your application working dir to ./target (or in a Maven property way: ${project.build.directory})
Solution:
By default, the maven surefire plugin executes its tests in the modules main directory.
In order to avoid this, set the workingdirectory of the plugin to the target directory.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>...</version>
<configuration>
<workingDirectory>${project.build.directory}</workingDirectory>
<basedir>${project.build.directory}</basedir>
</configuration>
</plugin>
Note that in case of tests that rely on some resources with root in the modules basedir, you need to copy these over. The easiest way i can find is with the resource plugin.
<build>
<resources>
<resource>
<directory>dependency</directory>
<targetPath>${project.build.directory}/dependency</targetPath>
</resource>
...
</build>
I can't tell you exactly how to do what you need to do because there is no real information
I can give you a hint about what to look at using.
Maven profiles can change the source, and behavior of Maven when they are selectively enabled.
Profiles are specifically designed to do just what you want to do.

Sonar: non-maven project -> exclude a directory in src

I have a non-maven project, but I have to use Sonar to make a code analysis once. So I created a pom.xml which works great. I see the analysis of all files and folders below my src directoy using this pom file:
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group.id</groupId>
<artifactId>arifactId</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>MyApplication</name>
<build>
<sourceDirectory>src</sourceDirectory>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
</project>
But I want to exclude one directory and all subdirectories of it. I have the two directories src/fr/ and src/com/. I only want to have src/fr/ and exclude src/com/.
Changing
<sourceDirectory>src</sourceDirectory>
to
<sourceDirectory>src/fr</sourceDirectory>
I get this error:
Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar
(default-cli) on project arifactId: Can not execute Sonar: Sonar is
unable to analyze file : '/Users/tim/workspace/src/fr/xxx/dao/TestClass.java':
The source directory does not correspond to the package declaration fr.xxx.dao
Normally, the The source directory does not correspond to the package declaration, as it told us, is an error when the package declared at the java file does not correspond with the directory structure e.g.
package my.test.java;
public class MyTest {}
The directory should be my/test/java/MyTest.java,
please note the src is treated as a sourceDirectory.
In your case you have changed the sourceDirectory from src to src/fr that means
package fr.xxx.dao;
public class TestClass{}
The directory is xxx/dao/TestClass.java,
please note the src/fr is treated as a sourceDirectory. Then the fr is ignored.
Normally when we would like to exclude somes package from the Sonar analysis, it can be simply done by setting them at each quality maven plugin e.g. findbugs,PMD, cobertura, etc.
Anyhow the Sonar also provides the configuration for each project as well. We can set by using the following steps: -
Please note: I'm using Sonar version 3.5, the menu may be different if you're using the different version.
Go to our sonar web site, e.g. https://myhost/sonar
Go to our project by selecting it from the dashboard.
At the top right you will see the Configuration menu. Click it and select Settings.
At the Settings page, select Exclusions menu.
At Exclusions you can simply set the excluded modules which is able to use the wildcard as well. (You may see the example at the bottom of the page.)
The example from your case, the exclusion should be fr/**. (Exclude all under the folder fr).
Please refer to the following link: -
Project Administration
Excluding Files and
Analysis Parameters
I hope this may help.

Resources