job-dsl-core jar version updated to 1.44 & githubPullRequest closure is not working

放肆的年华 提交于 2019-12-11 12:36:31

问题


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 ?


回答1:


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.




回答2:


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'
                            }
                        }
                    }
                }
            }
        }


来源:https://stackoverflow.com/questions/36505926/job-dsl-core-jar-version-updated-to-1-44-githubpullrequest-closure-is-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!