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 50 forks source link

Avoid Triggering from Deleted Branches #200

Open juanmacoo opened 2 years ago

juanmacoo commented 2 years ago

On the push event it would be nice to have a checkbox to avoid running from deleted branches.

This happens when you want to run the pipeline from all branches (Branch Specifier: **), and an event comes in with ref_change such as

"changes":[  
    {  
      "ref":{  
        "id":"refs/heads/test",
        "displayId":"test",
        "type":"BRANCH"
      },
      "refId":"refs/heads/master",
      "fromHash":"000000000000000000000000000000000",
      "toHash":"178864a7d521b6f5e720b386b2c2b0ef8563e0dc",
      "type":"DELETE"
    }
  ]
macghriogair commented 2 years ago

Interesting find, thank you! I cannot imagine a scenario where one would want to trigger a build on a deleted branch – git checkout would fail. But maybe I am unaware of some edgy use cases in the wild, e.g. a job that does some cleanup stuff ...🤔

We will look into this.

juanmacoo commented 2 years ago

I agree, maybe just avoid running all together would be better. but yeah I agree, who knows, maybe someone has some weird use case. Maybe it could be the inverse, a check box to run on Deleted branches.

I wouldn't use it but hey 🤷‍♂️ who am I to say what others should do.

Additionally I would like to add that this happened on branch(**) in a normal pipeline job (not multibranch), just in case it wasn't clear.

Gozke commented 2 years ago

It would indeed be cool if the plugin did not trigger in this case. We worked around this by specifying a branch filter for the push action. Something like this :(develop|release/|hotfix/).*

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

julioc-p commented 2 weeks ago

Is this issue still present? It seems I cannot replicate it.

RoggeHaj commented 4 days ago

I'd say this is still an issue. We have the following setup:

This setup works while working on feature branches as well as building integration branches on merge. The problem is that it will also trigger a build for the deleted branch with an error message similar to

Started by Bitbucket PPR: server repository event by user666
hudson.plugins.git.GitException: Command "git fetch --tags --force --progress --prune -- origin +refs/heads/feature/my-cool-feature:refs/remotes/origin/feature/my-cool-feature" returned status code 128:
stdout: 
stderr: fatal: couldn't find remote ref refs/heads/feature/my-cool-feature
fatal: the remote end hung up unexpectedly

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2846)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2185)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:635)
    at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:408)
Caused: java.io.IOException
    at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:413)
    at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:219)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:126)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:73)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:311)
    at hudson.model.ResourceController.execute(ResourceController.java:101)
    at hudson.model.Executor.run(Executor.java:442)
Finished: FAILURE