zarplata / concourse-git-bitbucket-pr-resource

:rocket: Concourse CI resource for tracking git branches of Bitbucket pull-requests
MIT License
34 stars 43 forks source link

Re-running a Failed Build Job Appends a New Build to PR #13

Closed dthagard closed 6 years ago

dthagard commented 6 years ago

Concourse CI Version

v3.14.1

Configuration

anchors:
  - &ci-callback-url
    url: https://<REDACTED>/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME

  - &pullrequest-hook-params
      name: ci test
      <<: *ci-callback-url

  - &ci-failure
    on_failure:
      put: pull-requests
      params:
        <<: *pullrequest-hook-params
        state: FAILED
        description: "Failed"

Debug Output

{"key": "ci test-16063", "description": "Failed", "repository": {"links": {"self": {"href": "https://bitbucket.org/!api/2.0/repositories/<REDACTED>/<REDACTED>"}, "html": {"href": "https://bitbucket.org/<REDACTED>/<REDACTED>"}, "avatar": {"href": "https://bytebucket.org/ravatar/%<REDACTED>%7D?ts=js"}}, "type": "repository", "name": "<REDACTED>", "full_name": "<REDACTED>/<REDACTED>", "uuid": "{<REDACTED>}"}, "url": "https://<REDACTED>/teams/<REDACTED>/pipelines/<REDACTED>/jobs/ci/builds/1", "links": {"commit": {"href": "https://bitbucket.org/!api/2.0/repositories/<REDACTED>/<REDACTED>/commit/<REDACTED>"}, "self": {"href": "https://bitbucket.org/!api/2.0/repositories/<REDACTED>/<REDACTED>/commit/<REDACTED>/statuses/build/ci%20test-16063"}}, "refname": null, "state": "FAILED", "created_on": "2018-08-16T19:00:14.306608+00:00", "commit": {"hash": "<REDACTED>", "type": "commit", "links": {"self": {"href": "https://bitbucket.org/!api/2.0/repositories/<REDACTED>/<REDACTED>/commit/<REDACTED>"}, "html": {"href": "https://bitbucket.org/<REDACTED>/<REDACTED>/commits/<REDACTED>"}}}, "updated_on": "2018-08-16T19:12:25.310277+00:00", "type": "build", "name": "ci test"}

Expected Behavior

After a failed CI build, if the user clicks the '+' button to trigger a new build of the same CI job and the job passes, the Bitbucket PR should show the build as passing.

Actual Behavior

After a failed CI build, if the user clicks the '+' button to trigger a new build of the same CI job and the job passes, the Bitbucket PR shows two builds on the PR--one passing build and one failing build. If the user has the merge check Check the last commit for N successful build and no failed builds enabled, the user will be unable to merge the PR until a new commit is pushed.

Steps to Reproduce

  1. Create a repository in Bitbucket Cloud.
  2. Create a branch permission on the default branch and set the merge check for Check the last commit for 1 successful build and no failed builds.
  3. Create a CI job in Concourse with the concourse-git-bitbucket-pr-resource configured to post back to the PR on_failure (see sample config above).
  4. Configure the CI job to fail by default.
  5. Create a new branch from the default branch.
  6. Commit a change to the new branch.
  7. Submit a PR to the default branch.
  8. Observe the failed build result.
  9. Fix the CI job to succeed.
  10. Re-run the CI job via the build trigger in the Concourse CI web console (or via CLI).
  11. Observe that two builds are posted back to the PR and that the user is unable to merge the PR.

Important Factoids

The current behavior when re-running a failed build on a PR in Bitbucket Pipelines is to set the key on the build status to the same key as the previous build thereby updating the same build status. This PR updates this resource to behave in a similar manner as the Bitbucket Pipelines product.

References

idr0id commented 6 years ago

Fixed in #14