I need to build two Maven projects which are available on Github. The first project produces a library which is needed by the second.
What is the recommended option to do it in Jenkins ?
Create a shell script which checkout and build both projects (in the correct order).
Use a pipeline ?
If you could provide any example/ relevant link that would be great. Thanks
You can achieve using 2 (upto my knowledge) options. Lets consider project A which builds libraries and project B is the dependent. I described below two options by considering two constraints.
Project B should be built whenever Project A is built
Project B can also be built alone if there is only changes with Project B but not with A
Option 1:
You have to create two "Maven Build jobs" for Project A & B. In Project B, you have to specify "Build whenever a SNAPSHOT dependency is built" under "Build Triggers".
This only applies when project B pom.xml has dependency of Project A built artifacts and the artifacts are SNAPSHOT. Below is the image of the same.
Options 2: You can create two Freestyle job for both Project A & B. Define Project B is downstream for Project A ( It can also be done vice versa ) using "Build Other Projects" under "Post-Build Options" of Project A.
And you can copy artifacts from Project A to Project B using Copy Artifact Plugin
Exception: Ideally the above step is not necessary, if your Project A artifacts are installed on $HOME/.m2/repository and Project B dependency defined in pom.xml (or) both project A & B are using Private Maven Repository option.
Assumption: I hope using single pipeline, it will be hard to manage this scenario. Though I expect somebody else will write with pipeline example to enlighten me as well :)
You can achieve this using Jenkins pipeline jobs.
First we need to create a folder for project A and in side that you can download the source code using GIT plugin and you can build the solution.
And create another folder and inside your download the source code of another project and you can build the second solution.
eg:
node{
stage('first project'){
dir('project1'){
git branch: '<Branch>', changelog: false, poll: false, url: '<First Repo URL>'
sh 'mvn clean install'
}
}
stage('second project'){
dir('project2'){
git branch: '<Branch>', changelog: false, poll: false, url: '<Second Repo URL>'
sh 'mvn clean install'
}
}
}
Sharing a method I used for building two changes.
Just add "Depends: xxxxxxx" before the Change-Id in your git commit message:
Depends: fe1a5effxxxxxxxxxxxxxxxxb8xxxx
Change-Id: Ig43j5cxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Related
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.
I am absolutly new in Jenkins and I have the following problem.
I have 2 jobs representing 2 different projects which are related to each other.
In particular I have the following situation:
I have a main project named main-project: this is a Java EE project. Then I have a Flex project named client-project that represent the web client of the previous project.
Both these project are stored in a specific GIT repository (so I have a specific GIT repository for the main-project Java EE project and another specific repository for the client-project).
The 2 projects (on my local machine) are related in the following way:
The main-project contains the .swf file that represent the compiled version of the client-project.
Something like this:
\main-project\src\main\webapp\Main.swf
So as you can see into the \src\main\webapp** directory of my **main-project is manually putted the Main.swf file that represent the compilation of the Flex client-project.
Ok, so my problem is: I have 2 Jenkins jobs related to these project.
1) main-project-job: that is the Jenkins job that compile and deploy on the srver the main-project project.
2) client-project-job: this job I think should do nothing (it only retrieve the latest compiled version of the client-project project.
I have to automate the building process in this way:
After that a dveloper push on GIT a new version of the main-project project the main-project-job compile and deploy it on server. When this job ends start the client-project-job that replace the Main.swf file into the **\DEPLOYED-PROJECT\src\main\webapp** path on my deployed project on the server.
How can I do something like this using Jenkins? Is it a neat solution to keep synchronized the latest version of the main-project and of the client-project?
> How can I do something like this using Jenkins?
Sounds to me like that's can be easily done with the Parametrized Trigger Plugin or something similar.
Just add a post-build step Trigger/call builds on other projects to main-project-job which will start client-project-job.
If that's not enough for some reason, please add further details on needed workflow.
Here a few leads that you might want to explore.
1. Deploy main-project-job with the embedded swf
As your main-project seems to depend heavily on your swf file (it should probably not be deployed without the swf file), can't you just get and put the swf file as part of the compiled main-project artifact ? It would seem logical to mee that your deployed main-project already contains the swf file at the time it is deployed.
With Jenkins pipelines, something like this would be pretty easy to do :
stage("Build main project") {
// your build step
}
stage("Copy client project to main webapp") {
git 'your-git/client-project'
sh "cp client-project/generated-swf /main-project/src/main/webapp/Main.swf"
}
stage("Deploy main project") {
// your deploy step
}
2. Copy swf file as part of the main job
If you cannot integrate the swf file directly to the main-project before deploy, you could still use the same job to do that, again if the main project heavily depends on the swf file, you probably want to copy it as part of the job. In this case, only the copy step will change and you will need to use some scp command to copy the swf file to the deployed app, on the distant server.
Something along these lines :
stage("Build main project") {
// your build step
}
stage("Copy client project to main webapp") {
git 'your-git/client-project'
sh "scp client-project/generated-swf user#deployServer:/main-project/src/main/webapp/Main.swf"
}
stage("Deploy main project") {
// your deploy step
}
3. Copy swf file as part of a separate job
If you are sure that you want to make the copy action as part of another job (let's say, if you sometimes needs to manually trigger the job to copy the modified swf file in the running webapp, on the server), you can just trigger another job from the main-project-job :
main-project-job
stage("Build main project") {
// your build step
}
stage("Deploy main project") {
// your deploy step
}
stage("Copy client project to main webapp") {
build job: copy-client-project
}
copy-client-project
stage("Copy client project to main webapp") {
git 'your-git/client-project'
sh "scp client-project/generated-swf user#deployServer:/main-project/src/main/webapp/Main.swf"
}
One last detail: if you do decide to use a separate job for copy, I would recommend not calling the job "client-project-job" which often implies a standard build/deploy job, instead I would name it "copy-client-files" or something similar.
I am testing the jenkins job-dsl plugin. I have an existing project where the setting 'Delete workspace before build starts' is enabled.
I have the following DSL defined:
job("$basePath/my-project") {
scm {
git {
remote {
name('origin')
url('git#bitbucket.org:my-organisation/my-project.git')
}
branch('*/develop')
extensions {
wipeOutWorkspace()
submoduleOptions {
recursive()
}
}
}
}
}
It seems this gives a configuration that is not really the same, it shows a "Wipe out repository & force clone" option. Are these options really the same thing in the end or are there different behaviours?
There is in general no difference between both options.
They are provided by different plugins:
Wipe out repository & force clone is part of the Git Plugin and only suitable as extension of the git plugin
Delete workspace before build starts is part of the Workspace Clean Plugin
The main differences between the Workspace Clean Plugin and the Git Plugin:
Not bound to Git SCM only
Allows the usage of ant file pattern to delete only some files or directories
An important behavior of the Git plugin's "Wipe out repository & force clone" option is that it will delete only the repository subdirectory if you have selected one in the "Check out to a subdirectory" option. It will leave the rest of your workspace alone. This doesn't appear in the documentation as far as I can tell.
You can achieve similar behavior with the Workspace Cleanup plugin by specifying the clone subdirectory in the "Pattern for files to be deleted" Advanced configuration section.
The end result is exactly the same, but in my observations the Git plugin deletion was 5 seconds faster than the Workspace Cleanup plugin.
I'm very new with Jenkins. I have tried to run projects on Jenkins but all are fail. I don't know whether the configuration is wrong or something. I have read the instruction on the jenkins-ci.org but I didn't understand anything. Anyone can give me a demo with Java project? By the way, show me the Jenkins configuration. Thanks all!
First question, do you want to build a Maven project?
If the answer is yes, you can create a new job with this template "Build a maven project".
You just have to configure your SCM tool (Git, SVN, ...) and when you want to pool your code (cron tab).
Next, in the build section, you have to declare your Maven goals (clean install for example) and the pom.xml file location (if the pom.xml file is not in the root folder).
That's all.
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