0

I am trying to create Jenkins job for GitHub Pull Request bulder using DSL script but my groovy script is giving error please correct my code if i am using incorrect syntax.

githubPullRequest {
        admin('user_1')
        admins(['user_2', 'user_3'])
        userWhitelist('you@you.com')
        userWhitelist(['me@me.com', 'they@they.com'])
        orgWhitelist('my_github_org')
        orgWhitelist(['your_github_org', 'another_org'])
        cron('H/5 * * * *')
        triggerPhrase('OK to test')
        onlyTriggerPhrase()
        useGitHubHooks()
        permitAll()
        autoCloseFailedPullRequests()
        allowMembersOfWhitelistedOrgsAsAdmin()
        extensions {
            commitStatus {
                context('deploy to staging site')
                triggeredStatus('starting deployment to staging site...')
                startedStatus('deploying to staging site...')
                statusUrl('http://mystatussite.com/prs')
                completedStatus('SUCCESS', 'All is well')
                completedStatus('FAILURE', 'Something went wrong. Investigate!')
                completedStatus('ERROR', 'Something went really wrong. Investigate!')
            }

    it / triggers / 'org.jenkinsci.plugins.ghprb.GhprbTrigger' / extensions / 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildStatus' / messages << 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
      message('All tests passed!')
      result('SUCCESS')
       }
    it / triggers / 'org.jenkinsci.plugins.ghprb.GhprbTrigger' / extensions / 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildStatus' / messages << 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
      message('An unknown error occurred.')
      result('ERROR')
  }
}
Jacob
  • 77,566
  • 24
  • 149
  • 228

1 Answers1

2

You can use the Configure Block syntax only within a configure block:

job('example') {
  triggers {
    githubPullRequest {
      admin('user_1')
      userWhitelist('you@you.com')
      orgWhitelist('my_github_org')
      cron('H/5 * * * *')
      triggerPhrase('OK to test')
      extensions {
        commitStatus {
          context('deploy to staging site')
          triggeredStatus('starting deployment to staging site...')
          startedStatus('deploying to staging site...')
          statusUrl('http://mystatussite.com/prs')
          completedStatus('SUCCESS', 'All is well')
          completedStatus('FAILURE', 'Something went wrong. Investigate!')
          completedStatus('ERROR', 'Something went really wrong. Investigate!')
        }          
      }
    }
  }
  configure {
    def messages = it / triggers / 'org.jenkinsci.plugins.ghprb.GhprbTrigger' / extensions / 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildStatus' / messages
    messages << 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
      message('All tests passed!')
      result('SUCCESS')
    }
    messages << 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' {
      message('An unknown error occurred.')
      result('ERROR')
    }
  }
}
daspilker
  • 8,154
  • 1
  • 35
  • 49