jenkinsci / jms-messaging-plugin

https://plugins.jenkins.io/jms-messaging
12 stars 37 forks source link

Need help with using jobdsl method of the plugin. #199

Closed bhavikbhavsar closed 4 years ago

bhavikbhavsar commented 4 years ago

It fails with below error

ERROR: (script, line 1) No signature of method: script.ciBuildTrigger() is applicable for argument types: (script$_run_closure1) values: [script$_run_closure1@7cc1c584]

I tried using the snippet shared in the readme.

ciBuildTrigger {
    providers {
      providerDataEnvelope {
        providerData {
          activeMQSubscriber {
            name("Red Hat UMB")
            overrides {
              def uuid = "4ba56bbc-959b-11e8-b83f-54ee754ea14c"
              topic("Consumer.rh-jenkins-ci-plugin.${uuid}.VirtualTopic.eng.ci.brew-build.test.complete")
            }
            // Message Checks
            checks {
              msgCheck {
                field('$.artifact.type')
                expectedValue("installability")
              }
            }
          }
        }
      }
    }
    noSquash(true)
  }
scoheb commented 4 years ago

Can you share your entire job-dsl script and let me know which version you are using please?

bhavikbhavsar commented 4 years ago

I am not sure about the syntax.

below is the pipeline syntax I am trying to convert to jobdsl.

#!/usr/bin/env groovy

properties([
        buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '1000', daysToKeepStr: '', numToKeepStr: '1000')),
        pipelineTriggers(
            [[
                $class: 'CIBuildTrigger',
                noSquash: true,
                providerData: [
                    $class: 'ActiveMQSubscriberProviderData',
                    name: 'Red Hat UMB',
                    checks: [
                        [field: 'state_name', expectedValue: '^done$'],
                        [field: 'name', expectedValue: 'idm'],
                    ],
                    overrides: [
                        topic: 'Consumer.rh-jenkins-ci-plugin.4dbbd20c-b315-4145-8fc3-2149be9af975.VirtualTopic.eng.mbs.>'
                    ]
                 ]
            ]]
        ),
        parameters([
                string(defaultValue: "", description: 'CI_MESSAGE', name: 'CI_MESSAGE'),
                string(name: 'MESSAGE_HEADERS', defaultValue: '', description: 'MESSAGE_HEADERS'),
                booleanParam(name: 'SKIP_UMB_MSG', defaultValue: false, description: 'True will cause no UMB messages.'),
                booleanParam(name: 'NOTIFY_PACKAGER', defaultValue: false, description: 'Notify packager about this jenkins build.'),
                booleanParam(name: 'DEBUG', defaultValue: true, description: 'Will printout debug information.'),
                string(defaultValue: "ftrivino@redhat.com", description: 'Email recipients', name: 'RECIPIENTS'),
        ])
])

String getVersion(String stream) {
    def matches = (stream =~ /el8.1/)
    if (matches) {
        return "RHEL8.1"
    }
    matches = (stream =~ /el8.2/)
    if (matches) {
    return "RHEL8.2"
    }
    matches = (stream =~ /el8.3/)
    if (matches) {
    return "RHEL8.3"
    }
    return "ERROR"
}

node() {
    stage('TriggerPipeline') {
            def pipeline
            def rhel_version
            script{
                def ci_message_json = readJSON text: params.CI_MESSAGE
                if ( ci_message_json.stream == 'DL1' ) {
                    pipeline = "ipa-server-ci-prod"
                    rhel_version = getVersion(ci_message_json.buildrequires.platform.stream)
                }
                if ( ci_message_json.stream == "client" ) {
                pipeline = "ipa-client-ci-prod"
                    rhel_version = getVersion(ci_message_json.buildrequires.platform.stream)
                }
            }
            print "TRIGGER: ${pipeline} ${rhel_version}"
            build job: "${pipeline}/${rhel_version}",
                parameters: [
                    [$class: 'StringParameterValue', name: 'CI_MESSAGE', value: "${params.CI_MESSAGE}" ],
                    [$class: 'StringParameterValue', name: 'MESSAGE_HEADERS', value: "${params.MESSAGE_HEADERS}" ],
                    [$class: 'BooleanParameterValue', name: 'SKIP_UMB_MSG', value: "${params.SKIP_UMB_MSG}" ],
                    [$class: 'BooleanParameterValue', name: 'NOTIFY_PACKAGER', value: "${params.NOTIFY_PACKAGER}" ],
                    [$class: 'BooleanParameterValue', name: 'DEBUG', value: "${params.DEBUG}" ],
                    [$class: 'StringParameterValue', name: 'RECIPIENTS', value: "${params.RECIPIENTS}" ],
                    ],
                wait: false
        }
}
bhavikbhavsar commented 4 years ago

JOb DSL version is 1.76

scoheb commented 4 years ago

I meant jms-messaging version.

but where is the snippet where you use ciBuildTrigger()?

bhavikbhavsar commented 4 years ago

jms-messaging version is 1.1.2

I am using the process job dsl section in the freestyle job to create the working listener first. image

ciBuildTrigger {
    providers {
      providerDataEnvelope {
        providerData {
          activeMQSubscriber {
            name("Red Hat UMB")
            overrides {
              def uuid = "4ba56bbc-959b-11e8-b83f-54ee754ea14c"
              topic("Consumer.rh-jenkins-ci-plugin.${uuid}.VirtualTopic.eng.ci.brew-build.test.complete")
            }
            // Message Checks
            checks {
              msgCheck {
                field('$.artifact.type')
                expectedValue("installability")
              }
            }
          }
        }
      }
    }
    noSquash(true)
  }
bhavikbhavsar commented 4 years ago

@scoheb any clue, if I am doing something wrongly?

scoheb commented 4 years ago

Some points:

bhavikbhavsar commented 4 years ago

Thanks @scoheb I have updated the plugin to latest version now. image

And my dsl looks something like below:

job('example') {
  ciBuildTrigger {
      providers {
        providerDataEnvelope {
          providerData {
            activeMQSubscriber {
              name("Red Hat UMB")
              overrides {
                def uuid = "4ba56bbc-959b-11e8-b83f-54ee754ea14c"
                topic("Consumer.rh-jenkins-ci-plugin.${uuid}.VirtualTopic.eng.ci.brew-build.test.complete")
              }
              // Message Checks
              checks {
                msgCheck {
                  field('$.artifact.type')
                  expectedValue("installability")
                }
              }
            }
          }
        }
      }
      noSquash(true)
    }

}

I still see the same error:

ERROR: (script, line 2) No signature of method: javaposse.jobdsl.dsl.jobs.FreeStyleJob.ciBuildTrigger() is applicable for argument types: (script$_run_closure1$_closure2) values: [script$_run_closure1$_closure2@3e12cf18]
scoheb commented 4 years ago

Please see https://jenkinsci.github.io/job-dsl-plugin/#path/job-triggers you are missing the triggers() section

bhavikbhavsar commented 4 years ago

Great! it worked. Thanks @scoheb for the help