stash-jenkins-postreceive-webhook icon indicating copy to clipboard operation
stash-jenkins-postreceive-webhook copied to clipboard

Debugging "Error: Jenkins Response: No git jobs using repository"

Open roxspring opened this issue 9 years ago • 25 comments

Over the last month our nicely working setup has deteriorated and no longer triggers Jenkins jobs from Stash, even after upgrading to v2.7.1. When we attempt to trigger jenkins from the webhook configuration check, it reliably results in an error saying "Error: Jenkins response: No git jobs using repository: ssh://[email protected]:8999/project/repo.git and branches:".

This is puzzling because there very clearly are git jobs using that repository.

But the stash log doesn't offer any extra insight into what exactly was attempted and therefore why it might have failed, and I can't identify anything obvious in the Jenkins logs either.

So what's going wrong here? And assuming the answer isn't obvious, how do I debug and figure it out?

roxspring avatar Aug 17 '15 15:08 roxspring

Turns out the underlying problem was that pollSCM had been disabled on the Jenkins jobs and therefore the plugin doesn't consider those jobs. The error message is misleading though and I'm still unclear how I was supposed to figure this out.

roxspring avatar Aug 18 '15 18:08 roxspring

What version of the Git plugin are you using in Jenkins?

mikesir87 avatar Aug 25 '15 20:08 mikesir87

@roxspring thanks! Glad I reached your post in due time - I was about to go berserk ;)

gaeste avatar Sep 29 '15 13:09 gaeste

I have had exactly the same problem as @roxspring and resolved it in exactly the same way.

I think that that error message in stash-jenkins-postreceive-webhook should be changed to reflect that the cause of the problem can also be lack of "poll SCM" setting enabled.

gdubicki avatar Oct 07 '15 08:10 gdubicki

You have to check the "Poll SCM" box, but you can leave the schedule empty. Very strange, but it seems to work.

jwcarman avatar Feb 05 '16 21:02 jwcarman

+1. This seems like a confusing UI. 'Poll SCM' makes it sound like the box needs to be ticked only if you want polling to happen, but it's mandatory for pushing jobs using the notifyCommit URL also.

andrewferrier avatar Feb 14 '16 09:02 andrewferrier

The thing about the polling is that it's not the notifier webhook's job. The webhook does not do the triggering of jobs... it simply pings Jenkins with a given repo name (and sometimes a bit of additional info in the GET url). Then it's up to Jenkins to do something with that info. It'll use the repo info to find Jenkins jobs for that repo. It's up to the job's configuration to be set to poll if you want that job to be trigger-able. When the job does its poll back to Stash, that's when it decides if it has a new commit to run a build against.

Remember, this plugin is installed in Stash, not in Jenkins... it's up to the Jenkins job to be configured correctly in order to utilize what the plugin is passing to it :-)

ashnazg avatar Feb 15 '16 03:02 ashnazg

we have a corner case i guess where even after following all the above setup instructions we are seeing a break of functionality with the following error

Error: Jenkins response: No git jobs using repository: ssh://[email protected]/tesc/ab.git and branches: develop No Git consumers using SCM API plugin for: ssh://[email protected]/tesc/ab.git

In Bitbucket the default branch is setup as develop but the branch to build in Jenkins configuration is user/abc/jira-1234

i am able to get the build to trigger from Trigger Jenkins on the bitbucket jenkins configuration to work by changing the default branch in bitbucket to user/abc/jira-1234.

clearly above is not a choice for us since we would like to keep the default branch as develop and the decided naming convention.

also another way to get around this is to change the bitbucket web hook config to say omit branch name but that just triggers builds on the default develop branch in Jenkins, not the one which is of the type user/abc/jira-1234.

Thank you very much in advance for your help and the plugin any help is really appreciated.

rajah1313 avatar Mar 22 '16 13:03 rajah1313

any updates ?

rajah1313 avatar Apr 04 '16 15:04 rajah1313

Hi, I've the exact same issue as @rajah1313 reported. Is it possible to get any progress here?

bastelfreak avatar Jul 08 '16 17:07 bastelfreak

Running into this as well for Multibranch Pipeline projects. There is no "Poll SCM" option that Im aware of. Not sure how to proceed.

coconitro avatar Sep 20 '16 21:09 coconitro

Using a Bitbucket Team Project. I added the SCMTrigger to my pipeline, still getting the same exception.

kevcodez avatar Dec 01 '16 17:12 kevcodez

I checked the omit branch name option and it works.

RishabhTayal avatar Dec 16 '16 17:12 RishabhTayal

We are having the same issue as the original post. Our jobs are all set to "Poll SCM". The "Omit Branch Name" option does allow it to trigger the job, but in our case, we need the branch name to be sent.

jlschrag avatar Jan 09 '17 04:01 jlschrag

Also having this issue

ryandavis84 avatar Jan 12 '17 20:01 ryandavis84

My Bitbucket project key is TSU. When setting up Bitbucket Server Webhook To Jenkins, it automatically generated the following URL

https://<bitbucket-server>/scm/tsu/<my-repo>.git

This did not work. Due to case-sensitivity.

I explicitly defined the project URL, by selecting the Custom option on Repo Clone URL, like this: https://<bitbucket-server>/scm/TSU/<my-repo>.git

It worked...

kevcodez avatar Mar 05 '17 15:03 kevcodez

is this only works for "master" branch, unable to get it working for any other branch e.g "develop"

samsixtyone avatar Apr 16 '17 20:04 samsixtyone

I run into this issue when setting BitBucket - Jenkins job. NOTE1: Jenkins Job ( I use BitBucket Team/Project and Multibranch Pipeline for this testing) NOTE2: I was not able to use Poll SCM option workaround, since the team/project or Multibranch Pipeline doesn’t have the option

I debugged this and it turned out the issue is coming from “git plugin” in my debug environment. (Jenkins “git plugin” code - https://github.com/jenkinsci/git-plugin )

In my local environment, this issue is solved after fixing the code.
Jenkins Multibranch(or BitBucket team/project) job is triggered when dev pushes the code or send “pull request”.

I did the following locally.

When sending webhook to Jenkins, “doNotifyCommit” in the GitStatus class is the entry point and it executes  “onNotifyCommit” function in the same class.   

My understanding is that "onNotifiCommit function in the GitStatus class" doesn’t support multibranch workflow. Therefore, I introduced the following function.

private List<ResponseContributor> onMultibranchJob(URIish uri,Jenkins jenkins,List<ResponseContributor> result) { for (final Item project : Jenkins.getInstance().getAllItems()) { SCMTriggerItem scmTriggerItem = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(project); if (scmTriggerItem == null) { String projectName = project.getFullDisplayName(); String [] jobs = projectName.split(" » "); if(uri.toString().toLowerCase().contains(jobs[jobs.length-1].toLowerCase())) { String className = project.getClass().getSimpleName(); if(className.equals("WorkflowMultiBranchProject")) { try { WorkflowMultiBranchProject wmp = (WorkflowMultiBranchProject) project; wmp.scheduleBuild2(0); result.add(new ScheduledResponseContributor(project)); } catch (Exception e) { e.printStackTrace(); } }

} } } return result; }

And, in the onNotifyCommit function, I added the following to support Muitlbranch job. result = onMultibranchJob(uri,jenkins,result); if(result.size() !=0) return result;

Git Plugin” project doesn’t have “WorkflowMultiBranchProject” dependency definition. Therefore, I needed to define the dependency in the project.

In my local environment, BitBucket - JenkinsJob(MultiBranch or BitBucket Team Project) is working fine with this fixing.

I recently joined DevOps job and I am very beginner for this type of setting.
So I may miss something basic. Please advice me.

kuniaki avatar Jun 06 '17 15:06 kuniaki

I forked the git plugin repo and submitted the code onto https://github.com/kuniaki/git-plugin.

Instruction:

  1. Clone code git clone https://github.com/kuniaki/git-plugin.git
  2. cd git-plugin
  3. Build mvn package (if you like to skip the testing, mvn package -DskipTests)
  4. Install hpi file to Jenkins You can find git.hpi in the git-plugin/target folder Go to Jenkins -> Manage Jenkins -> Manage Plugins -> Advanced.
    Click on “Choose File” button in the “Upload Plugin” and select the git.hpi file Click on “Upload” button.
    Start the installation.
    Please check “Restart Jenkins when installation is complete and no jobs are running"

In my environment, I don’t see the webhook error.

NOTE: I verified BitBucket webhook behavior. I don't test GitHub,GitLab etc....

kuniaki avatar Jun 07 '17 17:06 kuniaki

I am using pipeline and Bitbucket does not trigger new build. I have configured Jenkins hook and Jenkins webhook, as well as have pollSCM('') directive in my pipeline. Trying to trigger build from bitbucket receive such errors: Error: Jenkins response: No git jobs using repository: blablabla No Git consumers using SCM API plugin for: blablabla

sentinel09 avatar Jun 27 '17 13:06 sentinel09

I had the same problem, i'm just learning and I tried to call my local repository url but on jenkins was set the remote repository. I changed the hook to call the remote url and it works but i have the same "No Git consumers using SCM API plugin for:" stuff, curious what it is..

cristibaluta avatar Jul 28 '17 15:07 cristibaluta

It has to do with your specified Branch -

Branches to build Branch Specifier (blank for 'any')

if you set it to 'blank' or 'any' it works... I have been annoyed by this all morning.

hax0rdlux3 avatar Nov 02 '17 17:11 hax0rdlux3

@hax0rdlux3 I was told the same, but managed to make it work for a specific branch so this seems to not be the only way to fix. Also from design perspective :what if the job only concerns a specific branch only? For another project I am still not able to make it work (with branch a specific branch name) , it is annoying as the only difference I can see is the project and branch name.

menicolas89 avatar Feb 06 '18 18:02 menicolas89

Well, I made this workable. All our Bitbucket repositories are configured to build through Jenkinsfiles. In Jenkins I was configuring by adding these repositories as Bitbucket/Team project and and add "Override hook management". Do not forget to remove pollSCM('') from your Jenkinsfiles as it's excess in this hook strategy. After adding projects, repositories and branches, Jenkins will scan for repositories and adding them to system. Jenkins also itself will register hook in Bitbucket (Post webhooks) like https://your-jenkins.url/bitbucket-scmsource-hook/notify, which options you can change in Bitbucket for every repository. So using this strategy, will provide you build triggering, automatic repository addition (I can clarify details if need).

sentinel09 avatar Feb 06 '18 18:02 sentinel09

One point to note that may help others ..... go careful with the Payload URL on your webhook, one gotcha I've noticed is that there is some case sensitivity involved with Jenkins.

A payload URL of : https://jenkins.at.my.url/git/notifyCommit?url=https://github.corporate.com/foo/sample.git

would not trigger a multibranch pipeline with a git url of https://github.corporate.com/FOO/sample.git

Annoyingly the git webhook status is 200 in both working and non working cases, but in the broken case I saw the response body stating:

No git jobs using repository: https://github.corporate.com/foo/sample.git and branches: No Git consumers using SCM API plugin for: https://github.corporate.com/foo/sample.git

but in the working case the response body is:

No git jobs using repository: https://github.corporate.com/foo/sample.git and branches: Scheduled indexing of default ? jenkinsjobname

dibbles avatar Jun 28 '18 16:06 dibbles