2

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:

I cannot understand why this revision is chosen over the one sent in the hook.

Thanks a lot for your help!

torek
  • 448,244
  • 59
  • 642
  • 775
DavidL
  • 1,120
  • 1
  • 15
  • 34
  • Git seems to be behaving correctly: Jenkins is telling it to do a detached-HEAD checkout of the specified commit hash ID, and it does. So this is entirely a Jenkins issue: why is Jenkins specifying that particular hash ID? (I don't know the answer: Jenkins is often mysterious.) – torek Nov 24 '21 at 19:04
  • Does "_does not checkout the commit sent in the hook (different HASH from another branch)_" mean that the commit ID sent in the hook is from another branch than those who contains the `Jenkinsfile`? – Gerold Broser Nov 24 '21 at 21:42
  • The commit HASH sent in the hook (visible from Bitbucket interface) is the right one (i.e the one from the branch that contains the `Jenkinsfile`). As far as I understand, Bitbucket is doing its part correctly. – DavidL Nov 25 '21 at 07:41
  • HI @DavidL Since you are saying the changes made were on the same branch as the Jenkinsfile, can you see if you can trigger it manually (w/o making any other changes to the branch) and see if the exact commit hash is reflecting in the jenkins log ? This helps to see if the Jenkins has received the commit info from BitBucket or not. If it does receive the latest commit info now, then must have been some n/w glitch that prevented the commit info to reach Jenkins and you may then try with new commits this time. – Param J Nov 30 '21 at 22:05
  • Hi, sorry for the late answer. I've try to trigger the pipeline using Postman, and the result is the same: some out of space revision is checkout regardless of the HASH from the body of my request. – DavidL Dec 03 '21 at 14:51

1 Answers1

1

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.

DavidL
  • 1,120
  • 1
  • 15
  • 34