job-dsl-core jar version updated to 1.44 & githubP

2019-07-25 07:32发布

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 ?

2条回答
【Aperson】
2楼-- · 2019-07-25 07:34

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.

查看更多
Bombasti
3楼-- · 2019-07-25 07:58

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'
                            }
                        }
                    }
                }
            }
        }
查看更多
登录 后发表回答