Unable to trigger builds for "release/" branches - jenkins

We have branches set up like this:
origin/develop
origin/release/1.0.0
origin/release/1.1.0
Bitbucket
In the BitBucket, we have added Hook called "Bitbucket Server Webhooks to Jenkins" & Automatic merging is enabled.
Under the Advanced Configuration:
Branch Options is set to All and refs/remotes/origin/develop refs/remotes/origin/release/* in the input box.
Jenkins
For Jenkins, under "Source Code Management" section and "Branches to Build" option we have added the following:
Branch Specific (blank for 'any'): ${Branch}
Branch Specific (blank for 'any'): **release/*
Problem
Jenkins picks up build when we push to develop. Nothing happens when we push to any of the release branches.
Also tried manually: http://server/job/Jenkins%20Bitbucket%20Test/buildWithParameters?Branch=release/1.0.0, but this triggers a build for release/1.1.0 and not release 1.0.0.

The syntax is of the form: REPOSITORYNAME/BRANCH. In
addition, BRANCH is recognized as a shorthand of */BRANCH, * is
recognized as a wildcard, and ** is recognized as wildcard that
includes the separator /. Therefore, origin/branches* would match
origin/branches-foo but not origin/branches/foo, while
origin/branches** would match both origin/branches-foo and
origin/branches/foo.
Therefore my **release/* needs to be *release/**

Related

How to force circle ci build on master branches if commit message contains [ci skip]?

The build is skipped when a pr that contains [ci skip] in the squashed commit, gets merged into master.
Is there a way in CircleCI to force the build to run on master? Can we ignore [ci skip] for branches?
Or do I need to ensure that upon merging I strip out [ci skip]?
The string [ci skip] will need to be removed from the commit message in order for the merge to master to build.
Simply navigate to the project's page in CircleCI and select which branch you wish to trigger automation for with the drop-down menu. Then click "Trigger Pipeline".
There are a few other ways a [ci skip] tag can be ignored:
The build is associated with a forked PR
The build is associated with a scheduled build
The build is generated from the "Trigger a new pipeline" API endpoint
The build is triggered via a tag
You include it at the end of a commit body that has more than 247 characters
Sources:
https://support.circleci.com/hc/en-us/articles/360048785251-Why-Is-ci-skip-or-skip-ci-Not-Working-
https://circleci.com/docs/skip-build/

Bitbucket hook build from branch does not work for Jenkins

I have Jenkins with a job for SonarQube analysis, with the following value:
GIT SSH URL - set correctly
Branch Specifier - "**"
In Bitbucket, I have given the following value:
Jenkins URL - http://101.101.101.101:8080/Jenkins
Skip SSL Certificate - Enabled
Omit SHA1 Hash Code - Unchecked
Omit Branch Name - Unchecked
Omit the Trigger Build Button - Unchecked
Advanced Config:
Committers to Ignore - Blank
Branch Options - Build All selected and Blank field
I want Bitbucket to trigger Jenkins only if code is merged (from a pull request) to particular branch.
I tried the following settings in Bitbucket:
Branch Options - Build From selected and "release/Integeration" in the field
Still changes to every branch is triggered.
I tried this in Bitbucket:
Branch Options - Build From selected and "ref/heads/release/Integeration" in the field
Now nothing gets triggered.
Assuming you use HOOK from Bitbucket with the plugin Parameterized Builds for Jenkins and assuming you set a job using that plugin in Bitbucket. If so, did you define the pull request (PR) trigger only?

Jenkins throws java.lang.IllegalArgumentException: Invalid refspec refs/heads/** Error

I am trying to activate a pipeline on any merge request change. This works as long as my pipeline script is in Jenkins UI. Now I outsourced my script on GitLab, and the checkout should happen via the pipeline via scm option.
But all I get on build (yes, it triggers) is:
java.lang.IllegalArgumentException: Invalid refspec refs/heads/**
This happens if I leave the branch specifier empty, this is because I want to listen to any change. If I specify the branch, the build goes through.
My refspec:
+refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*
Most likely this is a Jenkins bug. https://issues.jenkins-ci.org/browse/JENKINS-46588
There seems to a solution anyway:
In your project configuration under Pipeline -> SCM -> Branches to build -> "Branch Specifier (blank for 'any'):
Do not use blank for any or * or .* or **. Use:
*/*
Another workaround would be to disable Lightweight Checkout.
PS:
Big thanks to ChrisAnnODell and Omurbek Kadyrbekov for linking the solutions in first place.
I'm still a bit puzzled that there is no fix for over 2 years now...

Jenkins gerrit trigger not fetching my change while building

I have configured jenkins with gerrit trigger plugin to validate every commit we push to gerrit.
I am expecting this trigger to include my latest change with original repo and make a build.
But, it is cloning only repo project and compiling without my change.
Below is my configuration settings for gerrit trigger in jenkins.
Refspec: $GERRIT_REFSPEC
Branches to build: $GERRIT_BRANCH
Build trigger: Gerrit event
Trigger on: patch set created
Gerrit project: added project and branch
Below is the build output message
Triggered by Gerrit: http://ci-test1/22
Building on master in workspace /var/lib/jenkins/jobs/Build_Adserver_4.7/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Build_Adserver_4.7/workspace - hudson.remoting.LocalChannel#733aee56
Using strategy: Default
Last Built Revision: Revision 701a75ef38aa191ac1b806c48e6b3451671888f6 (ads/4.7)
Fetching changes from 1 remote Git repository
Fetching upstream changes from abc
Commencing build of Revision 701a75ef38aa191ac1b806c48e6b3451671888f6 (ads/4.7)
Checking out Revision 701a75ef38aa191ac1b806c48e6b3451671888f6 (ads/4.7)
[workspace] $ /bin/sh -xe /tmp/hudson1375188638196718521.sh
+ echo 'Started Build'
Started Build
+ echo ..................
..................
+ echo 'Build Finished'
Build Finished
Finished: SUCCESS
Here 701a75ef38aa191ac1b806c48e6b3451671888f6 is HEAD of repo branch and 8cbda558adcad4fb7eb714e0b3fb98a6fbf5811c is the SHA-id of my latest change trigged the build.
I verified from jenkins workspace also, it doesn't include my change.
sorry if I am missing any information to mention. Please let me know
please help me if I am missing anything here.
Using Jenkins 1.532.2 Git Client Plugin 1.6.2 Git Plugin 2.0.1 Git Trigger 2.11.0
Here are the steps for configuring the Gerrit Trigger (from memory, hopefully all works fine):
Install the plugin(s) "Gerrit Trigger", "Git Plugin" and "Git Client Plugin"
In the main jenkins config (HOME->Manage Jenkins), click on Gerrit Trigger.
Create the server and configure it. Use "Test Connection" to be sure it works.
At the end, under "Control" press "start" (No idea what that does or if it's actually needed, but I did that).
Go to your project's config (MYPROJECT->Configure)
Check "Gerrit event" under "Build Triggers"
In the newly added menu, select your server, your triggers, etc.
For Gerrit Project I used "Plain" with "MYPROJECT" as pattern
For Branch, I used "Path" and "**" as pattern (builds all branches)
Under "Source Code Management" (up from triggers in my UI), click on "Git"
Set the Repository URL, here $USER matches for me, but otherwise write the correct user $GERRIT_SCHEME://$USER#$GERRIT_HOST:$GERRIT_PORT/$GERRIT_PROJECT
Specify a branch: $GERRIT_BRANCH
Under "Repositories" on the right, click Advanced, for "Refspec" enter $GERRIT_REFSPEC
Click Add right below, and select "Strategy for choosing what to build"
Select "Gerrit Trigger"
Not very intuitive but it should work. I suggest making sure the correct SHA1 Ids are being built.
If run into Error stderr: fatal: Couldn't find remote ref $GERRIT_REFSPEC
You have to change the Choosing Strategy to Gerrit Trigger
Go to the configuration page of your job and then click on the 2nd Advanced button under the git section. Almost at the bottom there is a Choosing Strategy that you will need to change to Gerrit Trigger
This will cause Git to fetch the correct version for your build
Fixing small issues in Lewis answer, change the values to the following to ensure the latest SHA1 is built.
branch: $GERRIT_REFSPEC
REFSPEC: $GERRIT_REFSPEC:$GERRIT_REFSPEC
I am using Jenkins 2.15 and faced the Issue and got resolved with following settings.
In Git Advances add Refspec : $GERRIT_REFSPEC
Branches to build : $GERRIT_BRANCH.
In Addititional behaviors section select Strategy for choosing what to build and select gerrit Trigger.

Make jenkins auto build one a day but build only when there are source code changed

I have problem in configure jenkins to auto build and deploy java project. I want to build and deploy once a day. However this build only there are changes during the day. IF there is no changes, I don't want jenkins to auto build and deploy.
Note: that I used gitlab as source code management.
Can you help me with this configuration.?
Firstly, you should configure the Git SCM section at the top of the job config page to point to your GitLab repository.
Then you can use the built-in "Poll SCM" build trigger — this will periodically check whether your source code repository has changed — and if it has, a build of this job will be started.
If the repository has not changed since the last build, then no build will be started.
You can configure this trigger — whether using a cron-like syntax, or a shortcut like #daily or #midnight — so that Jenkins only checks the source repository once a day.
Additionally, you should make sure that the "ignore post-commit hooks" option is enabled. If you're using webhooks from your Git repository to start Jenkins jobs whenever a commit occurs, this option prevents your once-per-day job from being triggered for every Git commit.
Here's the detail document: "Jenkins CI integration"
http://doc.gitlab.com/ee/integration/jenkins.html
Update to match your comment.
You don't want to trigger the Jenkins build via webhook. It's ok.
You want to check the code change 1 time a day.
Example on Linux, build at 6:00 AM if there's any code change.
Install
https://wiki.jenkins-ci.org/display/JENKINS/PostBuildScript+Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Text-finder+Plugin
Build Triggers
Build periodically: 0 6 * * *
Execute shell
Like this
SINCE=`curl http://192.168.0.1:8080/job/MyJava/lastStableBuild/buildTimestamp?format=dd-MMM-yyyy`
cd /opt/code/myjava/
git log --pretty="%h - %s" --author=gitster --since=$SINCE --before=$SINCE --no-merges -- t/
Post Build actions
Post build task
Log text: commit
Operation: AND
Script: Your script to build your Java
Jenkins text finder
Also search the console output
Regular expression: Could not match
Unstable if found

Resources