How to execute package for one submodule only on Jenkins? - jenkins

I have a sbt project with 4 modules: module-a, module-b, module-c, module-d.
Each module can be packaged as a WAR. I want to set up a deployment on Jenkins that would build only one of the 4 modules and deploy it to a container.
In detail, I want to have 4 Jenkins jobs - job-a, job-b, job-c, job-d, each building only the defined module (a to d).
For now, I am using clean update test package as the command for the Jenkins sbt build, but this results in packaging all 4 modules that is not necessary.
I already tried project -module-a clean update test package but with no luck.

You may also like to execute project-scoped clean and test tasks as follows:
sbt module-a/clean module-a/test
The solution is slightly shorter and clearer as to what project the following commands apply to.
You don't need to execute update task since it's implicitly executed by test as described in inspect tree test.
There's a way to make it cleaner with an alias. Use the following in the build.sbt:
addCommandAlias("jenkinsJob4ModuleA", "; module-a/clean; module-a/test")
With the alias, execute jenkinsJob4ModuleA to have the same effect as the above solution.

Quote the argument to project, i.e. project module-a, and don't use a dash before the name of the submodule.
The entire command line for the Jenkins job would than be as follows:
./sbt "project module-a" clean update test

Related

Selenium with Cucumber - Jenkins | How to configure specific feature to run using TAGS in jenkins

My runner file in my local system
My Jenkins configuration
Feature structure
As per my requirement, I have created separate features
{IndiaTransaction,CreateTransaction,BrazilTransaction,Mexico Transaction.features}
The above syntax will run all the features But I want to run specific features in my Jenkins, So how to configure it? I have tried below 2 methods it is not working, please help me to resolve
You can add a build step with Execute shell in Jenkins for the project and use the command below:
mvn test -Dcucumber.options="--tags #CreateTransaction,#BrazilTransaction"
And you can remove the tags option in cucumber runner class because the same thing you can do with -Dcucumber.options="--tags #tagName" in the command line
Please make sure you are using same tags in the feature files as well as in the command line.

How can I automatically svn tag build artefacts with Jenkins?

I'm automating the following manual process with Jenkins:
Check out the trunk from svn
Build the code
Run tests
If the tests pass then tag the code and built artefacts
Steps 1-3 are working, but I need some help with tagging in step 4. There are some possible solutions that I've excluded:
The svn-tag plugin which has security issues and not developed
since 2015
The "tag this build" button which is a manual step and doesn't allow
me to select which files are tagged
Using svn command line tools on the slave, because I don't want to rely on them being install (and the same version as Jenkins), also I don't want to expose credentials to the build
Tools seem to be available for Git. Is there another way to do it for svn that I haven't thought of?
What about svn commandline?
Your could try to create a tag using shell :
svn copy http://svn/mywebsite/trunk http://svn/mywebsite/tags/2.2.1 -m "Release 2.2.1 - added new feature"
Source:
http://svnbook.red-bean.com/en/1.6/svn.branchmerge.tags.html
If it works, your step 4 could be a build step called : Execute Shell :
Just put your shell script in the text-area called command. You could use variables for your url, tag number, etc
Finally, you could create a jenkins plugin called svn command line tool to make life easier. Is not complex as many believe.

How to run a single module in a multimodule maven Project through jenkins

I have created integration tests as a maven multi module project. Each module represents an integration tests. When I do a build on jenkins it runs all the test , I couldnt find the option to run a single module ( in my case a test).
It seems very easy. In the Jenkins Configuration under Build check on the option to Build modules in parallel . This will help you to run individual module.
My Test project is a Maven project and it has a structure like :
BusinessGroupModuleParentTests
SomeBusinessLogicIntegrationTest
SomeOtherBusinessLogicIntegrationTest
I can invoke each test individually now

Play framework services integration testing in Jenkins CI

I want to use Jenkins CI for integration testing with Play framework. My scenario is as following:
I have 2 projects, Project A and B.
Project A depends on Project B. The dependency is as such that to run tests on Project A, I need to start Project B first.
I already have unit tests in Project A but I need to test the integration of Project A and B.
I am using SBT plugin to execute the SBT and the Project A and Project B are working fine separately.
I could not figure out a proper way to do it. The issue I am facing is that I need to run Project B as a pre-build step but the Project B must be kept in running state but Project B is ended as soon as the build step executes run action of sbt and finishes the build which I don't want.
The command I execute to run Project B is clean compile run which executes as an action to SBT launcher.
I tried SBT stage and then run the jar but that is also causing the issue that the jar halts the control of the build and Project A doesn't get a chance to start.
I also checked Spawning a process in Jenkins but I couldn't make it work too. I am using Ubuntu and I tried using nohup instead of daemonize as described in the link by adding it as Execute shell script build step and it starts the Project B server process and kills it after some time. I also don't think that it might be the only way to do what I want to do.
May be I am using Jenkins wrong or may be I need to look in another direction so any help on this is much appreciated.
I ran into a similar problem where I needed to free the console for running other stuff. I did something similar (i.e. creating a script with the sbt commands), then running the script with a nohup like so:
nohup ./myScript.sh &
and the Play! app runs just fine in the background.
Remember to use different ports in your case, since you're running two Play! apps.

Pass a dynamic parameter in Jenkins build

I want to pass a dynamic parameter in Jenkins in a scheduled job (this build runs every day at 3:00 am)
This works if I executed it in my linux command line:
mvn package -DintegrationTag=$(date +%d-%m-%y)
or
mvn package -DintegrationTag="$(date +%d-%m-%y)"
or
mvn package -DintegrationTag="$(date +"%d-%m-%y")"
with these 3 options this is what is executed, for example (this is what I want to do in Jenkins):
mvn package -DintegrationTag=16-09-2013
but any of these sentences, do not work in my Jenkins goals and options (because the dynamic parameter).
Is there any way to do it?
The solution:
Content of the file which constains the script:
echo "NOW=`date +%d-%m-%y`"> env.properties
Path of the properties file:
env.properties
In project, goals and options:
clean test package -DintegrationTag=$NOW
Inject environment variables to the build process = true
In a Build "execute shell" section add this
NOW=`date +%d-%m-%y`
mvn package -DintegrationTag=$NOW
Another option can be to execute a top level maven target in jenkins.
The first two steps of injecting the required variable value into the build environment remains same as the answer given by #Iker below.
In the third step, give goal as
clean test packageand then in Properties section within the 'Advanced' tab, giveintegrationTag=$<your variable name>
Note that this solution is useful when one creates a free style project in jenkins. For maven 2/3 projects,solution by #Iker is good:)

Resources