-
Bug
-
Resolution: Unresolved
-
Minor
-
None
as a jenkins administrator, and github administrator
i want my team to have access to rapid rebuilds in response to github events,
and i want my jenkins config to have minimal project-wise config to greater enable my team to introduce new projects with low overhead.
for example by integrating via github webhooks to jenkins's github organization folder project provider.
consider the difference between these two jobs.
- First, a freestyle project with "Triggers -> GitHub hook trigger for GITScm polling?" enabled.
- Second, a organization project folder with a github provider. There is no config gui section for triggers, and the only trigger option is a periodic scan cron.
Note: job triggered were dumped with this groovy script at the jenkins script console.
```
def jobFullName = "My Freestyle Projects/my-project"
//def jobFullName = "My Github Org/my-project"
// Get the Jenkins instance and the job
def job = Jenkins.instance.getItemByFullName(jobFullName)
if (job == null) {
println "Job not found: ${jobFullName}"
return
}
// Get triggers from the job definition
def triggers = job.getTriggers()
if (triggers.isEmpty()) {
println "No triggers found for job: ${jobFullName}"
} else {
println "Triggers for job '${jobFullName}':"
triggers.each { triggerType, trigger ->
println "- ${triggerType}: ${trigger}"
}
}
```
First the freestyle project, including a `com.cloudbees.jenkins.GitHubPushTrigger` trigger:
`def jobFullName = "My Freestyle Projects/my project"`
```
Triggers for job 'My Freestyle Projects/my project push test': - com.cloudbees.jenkins.GitHubPushTrigger$DescriptorImpl@2bd4b183: com.cloudbees.jenkins.GitHubPushTrigger@376a03ca[] Result: {com.cloudbees.jenkins.GitHubPushTrigger$DescriptorImpl@2bd4b183=com.cloudbees.jenkins.GitHubPushTrigger@376a03ca[]}
```
Second, the organization project, it includes only `com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger` triggers.
`def jobFullName = "My Github Org/my-project"`
```
Triggers for job 'My Github Org/my-project': - com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger$DescriptorImpl@363e5fee: com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger@1be9ee91[H H/4 * * *] Result: {com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger$DescriptorImpl@363e5fee=com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger@1be9ee91[H H/4 * * *]}
```
I think this is an implementation bug.
By my reading of the soruce code here
https://github.com/jenkinsci/github-plugin/blob/0c86f968d0aa157c74fcd8b6477095ab1aab0883/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java#L89-L90
it seems clear that the webhook secton of this plugin is purpose-built to scan all jenkins jobs and trigger builds where the job logical scm tuple from example `git@github.com/mygithuborg/myrepo.git` converts to `("github.com", "mygithuborg", "myrepo")` matches a github webhook with an html url for example `https://github.com/mygithuborg/myrepo` converts to (`"github.com", "mygithuborg", "myrepo")`
it appears this match would test positive in my case but when capturing logs, the last log emission from the delivered github webhook is
https://github.com/jenkinsci/github-plugin/blob/0c86f968d0aa157c74fcd8b6477095ab1aab0883/src/main/java/com/cloudbees/jenkins/GitHubRepositoryName.java#L82
suggesting that the only code path that this sample could have followed is the path where the trigger of type `com.cloudbees.jenkins.GitHubPushTrigger` was missing from the jobs. and I clarified that this is in fact the case earlier.
so what remains is a path forward.
I checked and by my thorough examination, there is no built in configuration option for a organization project folder using the github project project provider to elect to auto-configure com.cloudbees.jenkins.GitHubPushTrigger triggers for all jobs.
I imagine it's possible for me to install these jobs by hand, however i fear that any reconfiguration of the github project provider might wipe out these configurations, as well as the lack of a ui to exemplify that this option is on and must be checked to gain this feature seems both fragile and unhelpful for long-term operation.
pseudo-code follows, the following may exemplify the enrollment of github webhook triggers on a project folder
```
import com.cloudbees.jenkins.GitHubPushTrigger
import jenkins.model.Jenkins
// The name of the organization project folder
def folderName = "foo"
// Get the folder item
def folder = Jenkins.instance.getItemByFullName(folderName)
if (!(folder instanceof com.cloudbees.hudson.plugins.folder.Folder)) {
println "Item '${folderName}' is not a folder or doesn't exist."
return
}
// Iterate over all jobs in the folder
folder.getAllJobs().each { job ->
// Skip if it's not a job that can have triggers
if (!job.hasProperty("triggers")) {
println "Skipping non-job item: ${job.fullName}"
return
}
// Check if GitHubPushTrigger is already configured
def existing = job.getTriggers().get(GitHubPushTrigger.class)
if (existing != null) {
println "Already has GitHubPushTrigger: ${job.fullName}"
return
}
// Add the GitHubPushTrigger
println "Adding GitHubPushTrigger to: ${job.fullName}"
job.addTrigger(new GitHubPushTrigger()) // THIS IS PSEUDO CODE
job.save()
}
```
I hope that the change to enroll a new organization folder github project provider setting to enable this already-coded feature is a minimal change and fits the github plugin design goals.