git clone only on new change and archive scm - jenkins

I am using to Jenkins to pull code from git in every 10 minutes and then compiling, archiving it for other jobs to clone this workspace. Currently it's pulling code from git every time and then archiving every time.
I want to clone code from git only if there is any new change else it should skip and do not archive the workspace. Which plugin should I use and what configuration I should make in that?

So it sounds like you have a couple things going on here. Here is some possible suggestions that I use to meet similar needs:
1.) If you are only wanting your job to build when there is a change in your source control, in this case GIT, you can use the "Poll SCM" plugin. And then in there set a cron expression to run every 10 minutes.
"Poll SCM" plugin will check source control for any changes and build the job when it finds them. If this works properly your job will not build thus it will not archive anything unnecessarily.
2.) For archiving I would make sure to utilize the "Discard Old Builds" plugin and "Advanced" section to keep a rotation and retention policy for your jobs artifacts.
3.) You state "for other jobs to clone this workspace". Are you actually having other jobs pull in this jobs workspace? Or did you mean copy its artifacts? I ask because the workspace is temporary, in a sense, and you should pull the artifacts. There is a plugin for that as well called "Copy Artifact Plugin" that you can use and it allows for various options.
4.) An alternative to "Poll SCM" plugin, if it doesn't work or you do not prefer this, depending on your GIT setup you could also potentially setup a hook that will notify Jenkins of changes. There are various hooks depending on the GIT implementation.
Hope this helps!

Related

Check in not trigger all applications in Jenkins to rebuild, only one

My understanding of Jenkins is that, if you have a repo (say a Git repo) that is tied to a Jenkins build, a check-in will trigger a complete repo re-build. But if you have a number of applications as part of your repo, is there a way to limit which applications will rebuild in response to a check-in? If you make a change to one application, is there a way to set up your Jenkins build process to that that check-in triggers a rebuild of that application alone?
I'm sorry but your understanding is wrong... Jenkins and Git talk to each other using hooks and if these hooks are connected to your build, only then will they build the application/branch in your repo... So unless you have specified that everything must be built, then all the application will be built, otherwise the one you checked in ...will trigger only that build
If you want, you can create a new job and add the GIT SCM hook(during configuration) and do a check in, it will build only your project and any other project that is using the same hook- key point to note here :)
So if all your applications are building then you have a configuration issue
Hope this helps :)

How to make Jenkins execute job only for the files that triggered build?

I have an svn repo and a certain Jenkins job for the stuff therein. Using Jenkins svn plugin's "include regions" feature, I can configure Jenkins to poll changes in certain folders or filetypes. But that is for triggering the job. When the actual job starts to execute, how do I know what were the files whose change triggered the build?
I can easily grep the answer out of svn log in a shell script if there is only one commit that triggers the build. But if there is an unknown number of commits causing my Jenkins job to start, I'm in trouble.
I'm asking this because I want my Jenkins job to run certain analysis ONLY for those files whose change triggered the build.
Multiple commits pushed at once also can execute the script. So I think you are in trouble already. So please maintain a file in job's workspace such that for every build at the end it will save its commit id. In your script, now check from that commit to current (HEAD) diff and check for changes in your files as per your constraints. And now run your job if all the conditions are met. Hope this helps.
I assume this may be fixed, but just in case, there is also the "Last Changes plugin" from Jenkins.
https://github.com/jenkinsci/last-changes-plugin
That makes a diff between what was in that environment, and what is about to be pushed and gives you the result.

Jenkins Multiple SCM - All SCM's triggering build

I have a Jenkins job that includes an Android app and a common library. I use Jenkins' Multiple SCM plugin to download both git repos and then build and run.
The common library gets updated more frequently than the app, and sometimes these updates break compatibility with the App. When the App gets updated and committed, its generally guaranteed to have fixed any incompatibilities against the latest library version.
The jenkins job should trigger only for commits to the App. Under the common lib SCM, I have added "Don't trigger a build on commit notifications" as well as "Polling ignores commits from certain users" excluding "*".
However, this job still gets run when commits happen to the lib, resulting in a lot of broken build notifications. What am I doing wrong?
Thanks.
under SCM 'Advanced clone behaviors', select 'Polling ignores commits in certain paths' and set 'Excluded Regions' to '.*'
Maybe it's better to switch from polling to post-commit hook, like described here?

Jenkins, how to make only specific commits to SVN to trigger a build

I am currently triggering a new Jenkins build whenever a commit to SVN has been made. However, I would like to make another build where our database is deployed only if the Ant script deploying the database OR our SQL scripts has been changed in SVN due to a commit. Is this possible to do in Jenkins?
There is no way to do this out of the box. But you can achieve this through other means.
For the job, you only specify the SVN sources for which you would want to listen. The remaining svn sources can be added to the appropriate location using command line svn methods. Ensure that the command line execution will place and merge the existing sources that jenkins has got. You have to give the right destination options in the svn commands. I myself agree that this is not a very clean way to do, but at least there is a work around for that.
Have two jobs. The first job will be defined only on the required svn sources and you enable the poll option. This should trigger another downstream project which reads all source files. This job should not be polling svn and the actual build execution should be done here.

Conditional Builds (when something has changed) in jenkins

Is it possible to do conditional build in Jenkins? for example every 5 mins it checks source control for new commits and will only build if there has been changes? we are using git at the moment.
You can set up Jenkins to poll your VCS and build if there are changes but better would be to use a post-commit trigger. 'Polling must die: triggering Jenkins builds from a git hook' will give you the info on setting that up.
I use Build triggers -> Poll SCM and doesn't really see the problem in using that system.

Resources