jenkinsci / bitbucket-push-and-pull-request-plugin

Plugin for Jenkins v2.138.2 or later, that triggers job builds on Bitbucket's push and pull request events.
https://plugins.jenkins.io/bitbucket-push-and-pull-request
MIT License
47 stars 49 forks source link

Add examples to help / readme #337

Closed PhilippDehner closed 1 month ago

PhilippDehner commented 2 months ago

I'd like to use the triggers in my declarative pipeline script. I couldn't find any solutions in the internet, so maybe it would be nice to add it to the readme of the plugin.

My problem is: I’d like to trigger my pipeline after opening and updating a pull request in bitbucket. If I do the following, I get an error:

  triggers {
    bitBucketTrigger([
      pullRequestServerCreatedAction(allowedBranches: 'origin/(.*)', isToApprove: true),
      pullRequestServerUpdatedAction(allowedBranches: 'origin/(.*)', isToApprove: true)
    ])
  }
  stages {
    ...
  }
}

The error was: org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: ae121c1a-49a4-4ced-b330-a6e7130dd5fb java.lang.NoSuchMethodError: No such DSL method 'pullRequestServerCreatedAction' found among steps

julioc-p commented 2 months ago

Hi! You can take a look at testDslTriggerCreateUpdatedMergedApprovedPRAllowBranchesWithApproveActionsPipeline.groovy in the test.resources.dsl . You can find a lot of examples for many use cases in this resources folder as well

PhilippDehner commented 2 months ago

Hi! You can take a look at testDslTriggerCreateUpdatedMergedApprovedPRAllowBranchesWithApproveActionsPipeline.groovy in the test.resources.dsl . You can find a lot of examples for many use cases in this resources folder as well

Thanks for your replay. In my case I use declarative pipeline scripts. I did not find any documentation how to integrate the properties into my script...

julioc-p commented 2 months ago

Here is an example you can take a look at in the Readme: https://github.com/jenkinsci/bitbucket-push-and-pull-request-plugin#pipeline-script. Should be more specific to your case

julioc-p commented 1 month ago

Have you also tried this tool: https://www.jenkins.io/doc/book/pipeline/getting-started/#snippet-generator? You can then choose trigger in the "Declarative Directive Generator" and select the BBPPR Plugin and generate your declarative pipelines.