I'm trying to implement a new Jenkins pipeline using Jenkinsfile.
The GIT repository does not have a Jenkinsfile on every branch, just under a specific one (as I'm currently building CI stuff for a legacy repository).
Jenkins Pipeline is created with following configuration:
Discard old builds (I don't want to manually cleanup)
Bitbucket webhook trigger (on push event)
Pipeline script from SCM
Bitbucket server (using Bitbucket server plugin)
Authentication stuff
Branches to build: **
Script path: Jenkinsfile
Lightweight checkout is disabled
The webhook is automatically created in my Bitbucket repository, and builds are triggered just fine (when I push modification on the branch with the Jenkinsfile).
However, Jenkins does not checkout the commit sent in the hook (different HASH from another branch). As a result, build crashes as Jenkinsfiles do not exist on another branches (and will never exist on old legacy branches).
> git fetch --tags --force --progress -- http://mybitbucket:port/scm/vs/myrepo.git +refs/heads/*:refs/remotes/myrepo/* # timeout=10
Seen branch in repository myrepo/old-branch-a
Seen branch in repository myrepo/old-branch-b
...
Seen 40 remote branches
> git show-ref --tags -d # timeout=10
Checking out Revision 0a781a1bd4ad194aae911ce26d1ec4cd1e73dd76 (myrepo/old-branch-x)
> git config core.sparsecheckout # timeout=10
> git checkout -f 0a781a1bd4ad194aae911ce26d1ec4cd1e73dd76 # timeout=10
Commit message: "my commit message"
First time build. Skipping changelog.
Posting build status of INPROGRESS to mybitbucket for commit id [0a781a1bd4ad194aae911ce26d1ec4cd1e73dd76] and ref 'null'
ERROR: /var/jenkins_home/workspace/myrepo#script/Jenkinsfile not found
Technical context:
Jenkins 2.303.3 running in a docker container
Bitbucket server integration plugin
I cannot understand why this revision is chosen over the one sent in the hook.
Thanks a lot for your help!
I was misled all along.
Turn out that I need to use Multibranch pipelines instead of regular ones. It works well and create webhooks automatically as desired (using the right Scan Multibranch Pipeline Triggers configuration).
I'm still frustrated by the behaviour of regular pipelines, which makes no sense to me and seems poorly documented.
I've been trying to setup a build-trigger with a gitlab web-hook to my Jenkins freestyle project,
For that,
In Jenkins, added gitlab connection, added the ssh url and specified the branch I need to build in the git plugin's Branches to build section,
Also, with the Gitlab plugin installed, opt for the Build Triggeres > gitlab webhook url
As the next step, created an outgoing webhook in gitlab and added the url,
Now the webhook works and the build gets triggered on repo changes,
But the problem is Jenkins Builds the Project on different Branch when it gets triggered from web hook,
What I've done so far,
On checking further, when there is changes in multiple branches ie, origin/master, origin/feature, origin/test, The first one in the list ie the master getting build instead of the specified test branch.
When built from jenkins directly, It pulls the correct branch, no issues there,
I've modified the configuration as per this stack-overflow answer. such as mentioning the 'refspec' and adding advanced clone behaviours and shallow clone, but nothing seems to work,
comparing the git commands executed at the time of a direct jenkins build and a gitlab webhook-triggered build shows this difference,(with the refspec modifications)
# on successful build
> git fetch --no-tags --progress --depth=5 -- git#gitlab.com:<project_name>.git +refs/heads/test:refs/remotes/origin/test # timeout=10
> git rev-parse origin/test^{commit} # timeout=10
# when triggered via webhook (it switches to master at last)
> git fetch --no-tags --progress --depth=5 -- git#gitlab.com:<project_name>.git +refs/heads/test:refs/remotes/origin/test # timeout=10
> git config remote.origin.url git#gitlab.com:<project_name>.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/test:refs/remotes/origin/test # timeout=10
Avoid second fetch
> git rev-parse remotes/origin/master^{commit} # timeout=10
All branches with changes are showing in the build section instead of the test branch,
which is the only branch I need this project to pull from the remote,
Using Jenkins version 2.303.3 JDK 8, plugins version Gitlab: 1.5.22, Git : 4.10.0,
Can someone suggest any solution for this,
As of now, it is building the wrong branch only at the time of testing web-hook from gitlab,
On a regular change, the desired branch is build as specified in Jenkins and in gitlab, be sure to use the branch filter in gitlab if doing like this,
It is evident that when testing the web-hook, gitlab sends triggers for all branches that got changes, what happens in Jenkins I assume is it builds the default branch when receiving such triggers,
I have a Jenkins build job with
Source Code Management > GIT > Repository URL: https://GitHub_repo_url/branch_name
this will pull the the HEAD revision out of the branch.
How can I pull code of specified revision?
I have a Jenkins Bitbucket Team/Project job.
Inside the Jenkinsfile in my repository I use "git describe" to get the current tag.
After I updated to the latest Jenkins version (2.60.3) and updated most plugins, this fails because Jenkins doesn't fetch tags anymore.
This is what I had before the update:
Branch event
Checking out git https://bitbucket.org/xxxxxxx to read Jenkinsfile
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://bitbucket.org/xxxxx.git # timeout=10
Fetching upstream changes from https://bitbucket.org/xxxx.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials Admin user to clone bitbucket repositories
> git fetch --tags --progress https://bitbucket.org/xxxxx.git +refs/heads/master
This is what I have now:
Branch event
Checking out git https://bitbucket.org/xxxx.git into /var/lib/jenkins/jobs/xxxx/jobs/xxx/branches/master/workspace#script to read Jenkinsfile
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository https://bitbucket.org/xxxxx.git
> git init /var/lib/jenkins/jobs/xxx/jobs/xxxx/branches/master/workspace#script # timeout=10
Fetching upstream changes from https://bitbucket.org/xxx.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials Admin user to clone bitbucket repositories
> git fetch --no-tags --progress https://bitbucket.org/xxxx.git +refs/heads/master:refs/remotes/origin/master
This is the plugins I have installed:
Bitbucket Branch Source Plugin 2.2.3
Bitbucket Plugin 1.1.5
Git Client plugin 2.5.0
Git plugin 3.5.1
The default behaviour changed. It's not fetching tags anymore (uses --no-tags).
I couldn't find any settings to force jenkins to fetch tags.
In Bitbucket Team/Project settings, you can setup "Advanced clone behaviours":
Shallow clone
...
Do not fetch tags
"Do not fetch tags" is not selected. So I'd think that it should fetch tags by default...
Anyone having similar issue?
How can I force Jenkins to fetch tags in a Bitbucket Team/Project job?
I created a Jenkins issue and got some explanations (thanks to Stephen Connolly): https://issues.jenkins-ci.org/browse/JENKINS-46736
The solution is just to add the "Advanced Clone Behaviours" and to leave "Do not fetch tags" unchecked.
Having some major issues with Bamboo.
I run a rails project, that runs on Engine Yard.
My build strategy is as follows
Checkout from Source Code
bundle install
rspec (run tests)
Tag my build
(code to create tag causes new commit, tag used in deploy)
git remote remove origin
git remote add origin <my repo>
git tag Bamboo-${bamboo.buildNumber}
git push origin Bamboo-${bamboo.buildNumber}
In my deploy the way engine yard works is you deploy based on branches or tags ( there is no build artifacts)
So in my Deploy it's a single script that uses a gem https://github.com/engineyard/engineyard
and runs
ey deploy --environment <staging> --tag=Bamboo- ${bamboo.buildNumber} --app <my app>
Engine yard does all the rails 'stuff' to prep the build and deploy it. Really just need Bamboo to run test and if it works tag build.
PROBLEM
I am using bitbucket source control and have configured a hook to trigger a bamboo build on any commit to master.
The issue step 4) is pushing a tag which causes bitbucket to execute another build
Resulting in infinitely building bamboo.
Looking into how to solve this. Figured I could use Bamboo 'Exclude Changesets' and filter out a particular commit message
https://confluence.atlassian.com/display/BAMBOO/Bitbucket?focusedCommentId=610435557&#comment-610435557
so my 4) would now look like
git remote remove origin
git remote add origin <my repo>
#create tag
git tag -a Bamboo-${bamboo.buildNumber} - m 'bamboo build'
#push tag
git push origin Bamboo-${bamboo.buildNumber}
However as per the comments on that confluence page. Exclude Changsets isn't a visible option anymore?
I don't understand how I can stop this infinite building loop.
We use Bamboo and a tag doesn't kick off the build for us.
Our tag process is:
git tag -a v1.4.2 -m 'Production Release: [date]
git push origin --tags
Try using the --tags option when pushing.