Jenkins schedules 3 builds on first build - jenkins

I am creating a build that has 3 (sub builds) using the Parameterized Trigger Plugin to fire the builds I need built in a specific order.
The main build is using the Jenkins GIT plugin to monitor the repos I need so it can be triggered by a push to the branch I've declared.
The thing is, when I create the build at first (This is done through autojenkins) and trigger it to build, it builds but then in the middle of the first build a second build is scheduled and in the middle of the seconds build a third build is then scheduled, effectively building the same project 3 times in a row, although there has been no changes to the repos.
The reasons for build 2 and 3 are the same: Started by an SCM change but there is nothing to see in the polling log.
Can this behaviour be explained somehow?
Any help is greatly appreciated!
Here's some info on Jenkins:
Jenkins v 1.529 running on Ubuntu 12.04 on Amazon
Jenkins GIT plugin v 1.5.0
Parameterized Trigger Plugin v 2.20

Related

Jenkins trigger installation script for new build only

I am building a new Jenkins job to install the package once a new build is ready.
If I set the Jenkins job run at every hour, how to avoid install the same build?
Example:
Build 1.139.506 just ready
Then Jenkins kins job trigger installation for build 1.139.506
At next hour, Jenkins job is triggered again.
If build is still 1.139.506, then stop job, no installation needed.
Else, repeat step to install new build.
There are different ways to achieve what you need.
Use an SCM repository and do polls on the repo. So Jenkins will only run the Job if the source code changes.
Use an SCM and tag the source when you release a new version, in this case, you can run the Job if a new tag is created in the SCM.
Save the last deployed version somewhere and check if the current version is different from the last deployed version.
Check the deployment environment for the deployed version and check if the current version is different, if so run the Job, else skip.

Scan multibranch now builds every (also unchanged) job

We have setup multiple multibranch pipeline projects. When clicking on the button 'Scan Multibranch Pipeline Now' all jobs are triggered and built again. It does not matter whether or not there are changes, every job will just start building.
When everything is build and manually scan again, it works as expected and only changed jobs are built.
Running on Jenkins 2.164.2.
Changes detected: master (null -> b95ffd48bf9fd032004e150ae4188cf48d3c28b2)
Scheduled build for branch: master
We expect only the changed branches will be built again.
We ran into the same issue some time ago, but then I found this issue:
https://issues.jenkins-ci.org/browse/JENKINS-57588
Can you check if you have the same version of that plugin (Branch API 2.5.0) running in your Jenkins instance?
Upgrading Branch API plugin the newest version 2.5.2 (already fixed in 2.5.1) fixed the problem.

Jenkins Multi-branch pipeline doesn't schedule tag jobs

I'm trying to get Jenkins' multibranch pipeline job to build tags in a similar manner to branches. In Jenkins 2.73 (not sure when the functionality was added), Multibranch projects can be configured to retrieve both branches and tags from the source repository. Initially I thought this would be perfect for my needs (my Jenkinsfile can now build development or production builds from the same place in Jenkins).
Multibranch job with tags discovery configured
I have the build process itself up and running quite happily with a scripted pipeline, however my issue is that whilst the branch jobs pickup my triggers perfectly (Cron weekly) and are thus triggerable using the Git plugin's notifyOnCommit functionality (allows me to clean build weekly, but build on commit to the repo as well via a repo scan webhook), tag builds do not.
Has anyone else come across this? If so, have you found any reasonable way to resolve it?
Relevant snippet from my scripted pipeline (I tried with and without the overrideIndexTriggers setting):
properties(
[
pipelineTriggers(
triggers: [
cron('H 02 * * 7')
]
),
overrideIndexTriggers(true)
]
)
Polling configuration from a branch job generated by the multibranch pipeline seems fine
Jobs generated from tags by the multibranch pipeline do not receive the same configuration, bizarrely...
There is a note in the multibranch pipeline scan log that suggests that Tags will never be auto-scheduled:
Processed 8 branches
Checking tags...
Checking tag testing
‘Jenkinsfile’ found
Met criteria
No automatic builds for testing
Processed 1 tags
[Mon Oct 23 09:55:00 UTC 2017] Finished branch indexing. Indexing took 8.1 sec
Finished: SUCCESS
My project is docker based and I would like to run a release build weekly, to pull in any base-image changes etc.
Does anyone have any ideas about what I can do to get multi-branch projects to schedule tag builds?
Not automatically triggering a build for discovered tags seems to be by design according to JENKINS-47496. Stephen Connolly offers an explanation and suggestion for what you might do:
Stephen Connolly added a comment - 6 days ago
Tags are not built by default (because otherwise you could have a build storm when checking out a repository) and worse, the order tags will be built in is unpredictable... and you might have a Jenkinsfile that deploys to production when a tag is built.
There is an extension point in branch-api called BranchBuildStrategy which - if implemented - will allow deciding whether to build tags.
See https://github.com/jenkinsci/github-branch-source-plugin/pull/158#issuecomment-332773194 for starting point on how to create such an extension plugin... I believe there is some work on one at https://github.com/AngryBytes/jenkins-build-everything-strategy-plugin

How to build tagged version commit on Jenkins using researchgate/gradle-release

I am using Jenkins, which is the only one allowed to publish to our maven repository, and gradle-release plugin to tag a version and move to new snapshot version. I noticed the tagged version wasn't getting built because the push happens after the new snapshot version is committed -- hence Jenkins builds the new snapshot version and skips the tagged version. Is there a way to configure the gradle-release plugin to first do a push after the tagged version and then do another push for the new snapshot version?
I looked into the source code of the plugin and installed it locally to see how it works. It turns out that the createReleaseTag task and commitNewVersion tasks actually perform separate pushes. I also checked the commits and found that they had different timestamps. I reckon that while our GitLab may have fired two calls to the Jenkins webhook, the short time in between the two commits is insignificant that by the time Jenkins pulls the changes for the one triggered by createReleaseTag, the newer commit created by commitNewVersion will have already been pulled along.
The solution I have in my mind now is to either create separate Jenkins jobs for the branches and tags, or to introduce some time delay in between createReleaseTag and commitNewVersion.
Update Jan 12, 2017
I settled on using the https://wiki.jenkins-ci.org/display/JENKINS/Release+Plugin where the Jenkins job pulled from both master and develop branches. The Jenkins release plugin added a Release page where the release version and next snapshot version can be inputted and submitted to do the ff:
Check out master
Run default job (which should run tests)
Run release task
Check out new tagged version
Run publish task

Jenkins master holding back slave results

There are five jobs in sequential order(1,2,3,4,5). Jobs 2,3,4,5 are built successfully(but they have not come out of the execution shell), since the job 1 is still compiling. If I abort job 1 then all the results of 2,3,4,5 are updated spontaneously to gerrit.
How can I change this configuration in Jenkins master?
This is a known bug in the Jenkins mailer plugin, you need to upgrade the plugin to the latest version.
Here you can find more details:
Github - [FIXED JENKINS-20867] Never wait for a prior build to
complete merely
Jenkins - Sending mail blocks on prior build

Resources