2

We are planning to update job-dsl-core version to 1.44 from 1.42, but in the latest version pullRequest{} closure is deprecated and replaced with githubPullRequest{} closure as detailed in the migration document here https://github.com/jenkinsci/job-dsl-plugin/wiki/Migration#github-pull-request-builder. When I try to update our code with the above recommendation, I am getting following error:

No signature of method: javaposse.jobdsl.dsl.helpers.triggers.TriggerContext.githubpullRequest() is applicable for argument types: (com.xxx.dva.pipeline.generator.utils.JobUtil$_addGithubPullRequestBuilderConfig_closure2_closure22) values: [com.xxx.dva.pipeline.generator.utils.JobUtil$_addGithubPullRequestBuilderConfig_closure2_closure22@7e3918d6]
at sun.reflect.GeneratedConstructorAccessor17.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:198)
at javaposse.jobdsl.dsl.AbstractExtensibleContext.methodMissing(AbstractExtensibleContext.groovy:20)
at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:830)
at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1128)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1081)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:903)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:723)

The code change is:

Version 1.42

job.triggers {
        pullRequest {
            admin(JobConstants.GITHUB_PR_ADMIN)
            orgWhitelist(JobConstants.ORG_WHITE_LIST)
            cron('* * * * *')
            permitAll()
            allowMembersOfWhitelistedOrgsAsAdmin()
            triggerPhrase(phrase)
            onlyTriggerPhrase(useTriggerPhrase)
            extensions {
                commitStatus {
                    context('Pull Request Pipeline')
                    triggeredStatus('Build Triggered!')
                    startedStatus('Build Started!')
                    completedStatus('SUCCESS', 'Went green! Go ahead and merge ${ghprbSourceBranch} into ${ghprbTargetBranch}.')
                    completedStatus('FAILURE', 'Something went wrong. Click details!')
                    completedStatus('ERROR', 'Something went really wrong. Click details!')
                }
            }
        }
    }

Version 1.44

 job.triggers {
        githubPullRequest {
            admin(JobConstants.GITHUB_PR_ADMIN)
            orgWhitelist(JobConstants.ORG_WHITE_LIST)
            cron('* * * * *')
            permitAll()
            allowMembersOfWhitelistedOrgsAsAdmin()
            triggerPhrase(phrase)
            onlyTriggerPhrase(useTriggerPhrase)
            extensions {
                commitStatus {
                    context('Pull Request Pipeline')
                    triggeredStatus('Build Triggered!')
                    startedStatus('Build Started!')
                    completedStatus('SUCCESS', 'Went green! Go ahead and merge ${ghprbSourceBranch} into ${ghprbTargetBranch}.')
                    completedStatus('FAILURE', 'Something went wrong. Click details!')
                    completedStatus('ERROR', 'Something went really wrong. Click details!')
                }
            }
        }
    }

How can I fix this issue ?

inari6
  • 401
  • 1
  • 9
  • 19

2 Answers2

2

The built-in support for the GitHub Pull Request Builder plugin has been deprecated in Job DSL 1.43. The new syntax is provided by the version 1.29.7 or later of the GitHub Pull Request Builder plugin through an extension. So you need to update the GitHub Pull Request Builder plugin to 1.29.7 or later.

daspilker
  • 8,154
  • 1
  • 35
  • 49
  • We are using ghprb 1.31.2 in our jenkins and trying to configure it through job-dsl-core.Should I import gpprb in my mavenproject & use it ? org.jenkins-ci.plugins ghprb 1.31.3 I tried this & still the same error. Can you tell me how can I code this. – inari6 Apr 11 '16 at 17:11
  • 1
    You can't use DSL from an extension when running outside of Jenkins. I hope I can fix that in the future. But for now you can either ignore the deprecation warnings or you can use a [Configure Block](https://github.com/jenkinsci/job-dsl-plugin/wiki/The-Configure-Block) instead. – daspilker Apr 11 '16 at 19:28
1

The only way is to fall back to manual configuration block:

job.configure {
            def trigger = it / triggers
            trigger << 'org.jenkinsci.plugins.ghprb.GhprbTrigger' {
                adminlist JobConstants.GITHUB_PR_ADMIN
                whitelist ''
                orgslist JobConstants.ORG_WHITE_LIST
                cron '* * * * *'
                spec '* * * * *'
                triggerPhrase phrase
                onlyTriggerPhrase false
                useGitHubHooks false
                permitAll true
                autoCloseFailedPullRequests false
                commentFilePath ''
                allowMembersOfWhitelistedOrgsAsAdmin true
                extensions {
                    'org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus' {
                        commitStatusContext 'Pull Request Pipeline'
                        triggeredStatus 'Build Triggered!'
                        startedStatus 'Build Started!'
                        statusUrl ''
                        completedStatus {
                            'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
                                message 'Went green! Go ahead and merge ${ghprbSourceBranch} into ${ghprbTargetBranch}.'
                                result 'SUCCESS'
                            }
                            'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
                                message 'Something went wrong. Click details!'
                                result 'FAILURE'
                            }
                            'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
                                message 'Something went really wrong. Click details!'
                                result 'ERROR'
                            }
                        }
                    }
                }
            }
        }
Ma3oxuct
  • 240
  • 1
  • 3
  • 7