Triggering Maven Build on changes to particular directory in Jenkins - java

We have Github repository with the structure as:
Project Name
- submoduleA
- submoduleB
- submoduleC
Every submodule is an extra microservice present inside the same branch. It is maven project. Every submodule is having a seperate jar which are not having any build dependencies.
I want to setup a Jenkins job which will get triggered when there is some changes to the submodule directory and build the respective jar.
Is there any way we can achieve that or is my approach is not correct? I also want to integrate Sonarqube analysis with it.

I suggest you refer to these blogs to setup the automatic trigger process step by step, my favorite is the 3rd blog.
Trigger Jenkins builds by pushing to Github
Automatically triggering a Jenkins build on Git commit
Triggering a Jenkins build from a push to Github

Related

why the jenkins did not checkout the source code in multibranch build

when I build a multi pipeline project, I found the dictory only generate one dir:
an-superhub-multipipeline_hades
and the dir an-superhub-multipipeline_hades did not have source code. and other project have 3 dir like this:
an-superhub-multipipeline_master
an-superhub-multipipeline_master#libs
an-superhub-multipipeline_master#tmp
why would this happen, what should I do to fix it? I want to delete the branch and regerate it, but I did not find any delete option in the UI. Only one option to delete all multibranch.
Check logs first:
Job's logs;
System's logs (go to Manage Jenkins - System logs);
logs in jenkins home folder.
What are the differences between develop and hades branches?
If you want to recreate job in multibranch pipeline - delete it on gitlab side, then run scan on jenkins multibranch job, and create branch again.
From my point of view it is better to use Gitlab branch source plugin to automate jobs creation in jenkins and create webhooks in auto manner on gitlab side.

Manage multi module project

Current setup:
Maven
Spring Boot
Angular
12 maven project + 1 Pom project
Git
Jenkin
Currently i have separate 13 project.
Every time if i have to setup on another machine then i have to clone each project individually.
Also i did the Jenkin pipeline setup for auto build.
Looking for
Once i clone the single pom/main project , all other project should get cloned
If i take pull of the main project then all other projects code should get updated
Child project should get head revision every time i start the jenkin
build.
Want to keep separate repo for each sub projects so that it can be reuse in other project as i have multiple requirements.
Solution that i have thought of:
Maven Child projects
Git Sub modules
Issues facing in above solution
1. Maven Child projects
--> If we are using maven child projects then we are literally copying the sub projects in pom/main project.
In this case i cannot reuse the project. Every time i have to clone the project to use it.
For big project with number of team member working, merging issue will come.
2. Git Sub modules
--> This is best solution for me but when we create sub module it always point to commit not the head revision.
Every time i have to manually pull the latest code push it to parent project.
This approach we can not use in Jenkins.
Is there best approach which can resolve all the issue.
You can add git sub-modules by specifying what modules to be added from other repositories. A .gitmodules file will be created on root that will contain list of all submodules and other preferences of yours.
Creating git submodules for projects in different repositories
There are set of commands available that you can use to sync up the git module and all it's sub-modules.
Set of steps that you could take is:
Add all submodules in project using git submodule add [ssh or https path] e.g. git submodule add https://github.com/test
Add other submodules and push the changes
Fetch submodule content by running
git submodule init
git submodule update
or alternatively run git clone --recurse-submodules https://github.com/chaconinc/MainProject to get sub-modules as well
I would recommend that you read through this link and ensure your requirement is fulfilled by this.

Maven - staging deployment

I have a java project that is managed with maven.
When I commit the project into SVN it contains the pom files that are used by a central build/deployment engine.
I want to set up maven to deploy the war into my staging server (tomcat).
I don't have problem with the task itself.
My problem is that I cannot commit into the SVN information about the staging deployment procedure.
I would like to have a local pom file, extending the parent pom and doing an extra task (tha staging deployment); this could solve my problem because I could simply exclude this pom from SVN commit.
Is there any way to do such thing?
I suggest creating an extra aggregator for your local use. This aggregator will have your current aggregator (or your modules if you dont use aggregator) and the task to deploy. At your local computer, you should use this aggregator to build and install your project when ever you want to deploy the war.

jenkins hook not working - jenkins bitbucket

Hi i am using jenkins and bitbucket , i want to trigger a build in jenkins when ever i commit any thing to bitbucket repository .
in jenkins
i created a project called test_1
in configure section Build Triggers part i ticked Trigger builds remotely
i added a token TEST_TOKEN
when i type this in my browser url and execute the jenkins build is triggered
http://test.com:8080/job/test_1//build?token=TEST_TOKEN
In bitbucket
i added a jenkins hook
Endpoint : http://test.com:8080/job/test_1//build?token=TEST_TOKEN
Module name - empty
Project name - test_1
Token - empty
then commited some code to bitbucket via git , The jenkins build not running , seems that the trigger is not running . :/ how to solve this problem . please help me . thanks in advance :)
I had the same problem. #fmitchell is correct with his suggestions for these fields.
But it didn't work for me.
I use a normal POST Hook instead where I provide the whole URL:
http://USER_NAME:USER_TOKEN#YOUR.JENKINS.URL.COM:YOUR_PORT/job/YOUR_PROJECT_NAME/build?token=some_token_from_jenkins
eg: http://bob.miller#jenkins.example.com:8080/job/test_1/build?token=TEST_TOKEN
It seems to be that Bitbuckt is missing the last parameter "build" in its created URL, but I can't tell for sure.
------Update------
I found a better solution, where you don't only trigger your build but also be able do build different branches by different Jenkins projects:
Install Bitbucket Plugin at your Jenkins
Add a normal Post as Hook to your Bitbucket repository (Settings -> Hooks) and use following url:
https://YOUR.JENKINS.SERVER:PORT/bitbucket-hook
Configure your Jenkins project as follows:
under build trigger enable Build when a change is pushed to BitBucket
under Source Code Management select GIT; enter your credentials and define Branches to build (like **feature/*)
By this way I have three build projects, one for all features, one for develop and one for release branch.
And best of it, you don't have to ad new hooks for new Jenkins projects.
It should be:
Endpoint : http://test.com:8080/
Module name:
Project name: test_1
Token: TEST_TOKEN

Maven/Jenkins automatic download/copy

I'm in a team to develop plugins in java.
We got Maven, a repository and Jenkins,
And I got myself a debian-server to test my applications.
When I push my commits, this happens:
Push in repository, upload and build in Jenkins.
Users download these .jar files and upload these to their server
What I want to be happen:
There are two ways,
First: After building with Jenkins: Download these files,
Second: When pressing "maven build", maven builds my applications and copy these to my server
How can I do this?
(Sorry for my bad English: I'm German)
If I understand you correctly, following scenario should help.
create two jobs
first job builds your artifact and archives it: user will be able to download it, job is triggered by source modification
second job is only executed manually (and requires two plugins, listed below), copies artifacts from first job and then uploads them to the server
Following plugins you would need to install:
copy artifact plugin to enable jenkins to copy artifacts from another job
publish over ssh plugin to enable jenkins to upload binaries and run commands on remote servers
You want when you push your SCM repository, to get Jenkins build into your local projet (update your jars), then manipulate send your final build to your server. Is that you want ?
If yes, I think that plugin would be interesting :
http://evgeny-goldin.com/wiki/Jenkins-maven-plugin#Supported_Plugins
you can manage jenkins goals from your pom.xml but I am not sure if you can get jenkins build.

Categories