How to exit Jenkins job if SCM polling does not detect any changes? - jenkins

Windows Server 2016, Jenkins 2.107.1. We have GitHub repositories, Git repositories not in GitHub, and CVS repositories. This link...Can I restrict poll SCM job to be run only once in a day?, tells me that I can set the polling to happen only once a day (which is all that we want, in that the coders can check in, up to a certain time). It does not tell me how to exit out (not to continue with the rest of the build steps), if there are no changes (and, send out a message that there are no changes and thus will be no build tonight). We are not using pipeline. Thanks.

the poll scm plugin in by default will not run the job if there are no SCM changes, also you will get GIT polling logs to see the detailed information

Related

I have a use case which causes issues with Jenkins free style project poll scm

I have a free style project which will trigger on commits. I have kept poll scm which polls for commits in remote repository. This jenkins job actually make some changes to a file after checkout and then commits+push back to remote repository.
This push by jenkins job is actually triggering back a new build due to scm poll for new commits is set in job. I want this job not to trigger again for self commit by job itself
It is not clear if you are using Git. In case you are and expect that the file will be always be changed by Jenkins, Git plugin in freestyle has options to ignore certain file paths.
If this specific file is expected to edited by user other than Jenkins than only solution I can think of is through conditional logic in jenkins pipeline-as-code.

Jenkins Job cancelled during the quiet period still builds

I'm using the polling scm (git) plugin to trigger jobs. I've set the quiet period to 30 seconds for a specific job.
When I commit:
the job indeed sits in the "build queue" for 30 seconds.
I cancel it, and it goes away
However the polling scm plugin seems to re-trigger and then build the job. at the next poll period
How do I cancel the job without letting it start, and then canceling it?
This is not possible with timer triggered scm polling.
The reason is, that on each poll jenkins will compare the remote to the local revision and will find out that the remote revision it is newer thus triggering a build. Aborting the build before a checkout or update doesnt change the local revision so it will retrigger a build on the next poll triggered by the timer.
A solution is, to make use of post-commit hooks.
Post-commit hooks are configured on the remote machine and are basically scripts that run after a commit has happened. As you can trigger a poll by calling some url on your jenkins server, its merely some configuration on the scm server to trigger a poll exactly after a commit has happened. That way, after an abort, jenkins will only trigger a poll on the next commit to the repository.
Theres usually some hints how to setup this in the documentation of the various scm plugins, i.e. the git plugin.

How to trigger jenkins Job on code pushed to development server?

I have development code repository at bitbucket and another test script code repository at bitbucket. Now I have setup a Jenkins job by linking test code repository. Is there any way to trigger jenkins job automatically on change in development repository ?
You can add the BitBucket Plugin to your Jenkins instance. It will allow you to configure a webhook in BitBucket that will then trigger any Jenkins job listening for that webhook. The plugin's page has a detailed breakdown, but the basics are;
In your repo in BitBucket, create a new Webhook using your Jenkins' url. I believe the url is generally http://[your jenkins url]/bitbucket-hook/
Make the trigger a repo push.
In your Jenkins job, check the box "Build when a change is pushed to BitBucket" under the Build Triggers section.
Now any time you commit to the repo you created the Webhook on, that Jenkins job will be run.
You can also limit what branches trigger commits by parameterizing your Jenkins build to ignore certain branches / keywords / etc if that's something you need for your specific project.
Builds by source changes
You can have Jenkins poll your Revision Control System for changes. You can specify how often Jenkins polls your revision control system using the same syntax as crontab on Unix/Linux. However, if your polling period is shorter than it takes to poll your revision control system, you may end up with multiple builds for each change. You should either adjust your polling period to be longer than the amount of time it takes to poll your revision control system, or use a post-commit trigger. You can examine the Polling Log for each build to see how long it took to poll your system.
Alternatively, instead of polling on a fixed interval, you can use a URL trigger (described above), but with /polling instead of /build at the end of the URL. This makes Jenkins poll the SCM for changes rather than building immediately. This prevents Jenkins from running a build with no relevant changes for commits affecting modules or branches that are unrelated to the job. When using /polling the job must be configured for polling, but the schedule can be empty.

Run Jenkins build for whichever branch was checked into on Gitlab

I recently made the transition from Subversion to Git for all my repos at work. However, with svn we had commit hooks in place so that our Jenkins job would run for whichever branch was checked into. Now, I'm trying to set this up using Gitlab and there appears to only be one place to add a web hook. It looks like any time something is checked into ANY branch, the web hook will run. Meaning if I have a branch_A associated with jenkins_job_A, something could be checked into branch_B and the commit hook for jenkins_job_A will still run. Is there a branch by branch way to configure these web hooks? Or is there some kind of script I can check into each branch that will act as a commit hook? Or (my fear) is this feature not supported in Gitlab?
I guess you set up GitLab to do a post commit request to http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>? In theory this should trigger the polling on all jobs that are configured with that URL, and in the polling step the jobs should decide whether they should build or not. In practice this will unfortunately cause all jobs to fire.
We worked around this issue by moving the Job configuration into a Jenkinsfile and then use a Multibranch Pipeline.
As an alternative you could also install the GitLab plugin for Jenkins and use the Jenkins integration in GitLab. This will allow you to trigger the correct jobs when commits are pushed on a branch. The downside is that it requires a per-job configuration.

executing jenkins job based on svn update?

I am creatig a new Jenkin Job. This job is using SVN version control and coding is done in Java and also i am creating jar using ANT.
Now I would like to create job that detects changes in svn repository.
i.e., When ever the developer changes the code jenkins job need to executed automatically.
Can any one please help me.
Thanks
Have you given Subversion Plugin a read?
Post-commit hook is of concern to you -
Jenkins can poll Subversion repositories for changes, and while this is reasonably efficient, this can only happen up to every once a minute, so you may still have to wait a full minute before Jenkins detects a change.
To reduce this delay, you can set up a post commit hook so the Subversion repository can notify Jenkins whenever a change is made to that repository.

Resources