Closed ntfc closed 5 months ago
Seems to be a JobDSL limitation: https://issues.jenkins.io/browse/JENKINS-64553 😭
Ok! Thanks for reporting. Will probably help other users if they have this problem.
I crafted a nasty workaround that could help solving this, basically have the seed job trigger a downstream pipeline job that in turn uses the Groovy API to manually call the JobFinderImpersonater#onUpdated
.
Here is its definition in case it helps others:
stage("call generic-webhook-trigger JobFinderImpersonator") {
def upstreamProject = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)?.upstreamProject
if (upstreamProject == null) {
error "Job must be automatically triggered by seed job and not manually executed"
}
def seedJob = Jenkins.instance.getItem(upstreamProject)
if (seedJob == null) {
error "Seed job ${upstreamProject} does not exist"
}
def gwtExtensions = Jenkins.getInstance().getExtensionList(JobFinderImpersonater.class)
if (gwtExtensions == null || gwtExtensions.size() == 0) {
error "Could not find the JobFinderImpersonator extension from the generic-webhook-trigger plugin."
}
if (gwtExtensions.size() > 1) {
error "Unexpectedly found more than 1 JobFinderImpersonator from the generic-webhook-trigger plugin."
}
def gwtJobFinderImpersonator = gwtExtensions.get(0)
def lastBuild = seedJob.lastBuild
def generatedJobsAction = lastBuild.getAction(GeneratedJobsBuildAction)
if (generatedJobsAction == null) {
echo "No generated jobs found in last seed job build '${lastBuild}'."
return
}
def generatedJobs = lastBuild.getAction(GeneratedJobsBuildAction).items
echo "Last seed job build '${lastBuild}' has generated ${generatedJobs.size()} jobs."
generatedJobs.each {
echo "Sending ${it.getDisplayName()} to generic-webhook-trigger"
// we can send everything since it will be filtered by the plugin
gwtJobFinderImpersonator.onUpdated(it)
}
}
This should require approving the following method signatures in script approval:
method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
method hudson.model.Run getCause java.lang.Class
method hudson.model.Cause$UpstreamCause getUpstreamProject
staticMethod jenkins.model.Jenkins getInstance
method hudson.model.ItemGroup getItem java.lang.String
method jenkins.model.Jenkins getExtensionList java.lang.Class
method hudson.model.Job getLastBuild
method hudson.model.Actionable getAction java.lang.Class
method javaposse.jobdsl.plugin.actions.GeneratedJobsBuildAction getItems
method hudson.model.listeners.ItemListener onUpdated hudson.model.Item
Opened https://github.com/jenkinsci/jenkins/pull/9304 to fix the issue from JENKINS-64553 which also solve this here
Fix will be included in next LTS 2.452.2
Also tested it works as expected now with 2.460.
Thank you @mawinter69 !
Continuing this in #319
Jenkins and plugins versions report
Here is my system info (other plugins omitted):
Hi,
I am running into an issue registering an existent job to use the generic webhook plugin. This job was previously relying on a git push trigger and even though it is now shown as correctly configured in the UI to use the generic webhook, it is not being returned on the webhook response until I restart Jenkins or manually re-save the job.
I can reproduce it by:
/generic-webhook-trigger
response.JOBS_WITH_GWT
in https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/3954ee99f8c8801877f6a9b998fe7fdcaa78e6d7/src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java#L99/generic-webhook-trigger
response.It seems that somehow the plugin is not picking the event where the job is updated, but looking at the code it seems totally correct so I am not even sure where the issue is.
I am currently reproducing this using a parameterized job (boolean parameter
USE_GENERIC_WEBHOOK
) that processes the following JobDSL:I am not entirely sure if this is a problem with this plugin or JobDSL but maybe others have found (automated) ways around this or there is a way to fix in this plugin.
Thanks in advance!