I have a multi module gradle project and trying to configure build in Jenkins web interface.
Also I need possibility to choose module or build the whole project, then create docker image and upload it to the repository.
I've created Choice parameter with variable $PROJECT and module enumeration, like this:
module1
module2
module3
Then I added stage Invoke gradle script.
If I add gradle task $PROJECT:clean $PROJECT:build $PROJECT:jib, it will work fine for the selected module. But if I don't select module, it won't build the whole project, because of
$ /var/lib/jenkins/tools/hudson.plugins.gradle.GradleInstallation/gradle7.1.1/bin/gradle -DGRADLE_TASK= -PGRADLE_TASK= :clean :build :jib
Task 'clean' not found in root project 'name_of_project'.
Tasks have unnecessary : symbol if module was not selected.
If I add gradle task clean build jib it will do these tasks for the whole project always no matter which module is selected.
Also I tried to create stage Run shell command before Invoke Gradle script with this code:
GRADLE_TASK="clean build jib"
if [ -z $PROJECT ]
then
GRADLE_TASK="$PROJECT:clean $PROJECT:build $PROJECT:jib"
fi
And use it in gradle task field like this:
$GRADLE_TASK
But it doesn't take effect, because of:
/var/lib/jenkins/tools/hudson.plugins.gradle.GradleInstallation/gradle7.1.1/bin/gradle -DGRADLE_TASK= -PGRADLE_TASK= $GRADLE_TASK
Task '$GRADLE_TASK' not found in root project 'name_of_project'
I tried some variants of this variable, but it doesn't work too:
- $GRADLE_TASK
- ${GRADLE_TASK}
- "${GRADLE_TASK}"
- GRADLE_TASK
Can anybody help with this problem?
Related
I am building a gradle project and the source code is in git. After checking our repo to jenkins' workspace, how do i have jenkins go to a sub-directory and do the build?
I tried adding shell commands but cd will not work as it executes script on a separate shell.
If you are building a gradle project, perhaps you should use the "Invoke gradle script" step rather than a shell script?
As part of the gradle build script, it has an option to specify the "Root Build script", which will let allow you to specify a subdirectory if you wish.
See the Gradle plugin for more information.
There are a number of module in SVN branch and for build purpose we have one main build.xml which will trigger all the modules for build, we are using jenkins to invoke ant . Post build it will generate say five or six EAR ,now the problem is i want to trigger build only for one module which will have a new check in without changing the existing directory structure of branch in svn repo as jenkins will trigger build for all the module once it will find a check in in repo.
Create a new jenkins job for required module only. Use your main build.xml as the input of the ant task but put the module name ( or related target ) as Targets in jenkins task. If you have module specific build.xml then feed that file in this new Jenkins job.
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
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:)
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