SHyx0rmZ / bitbucket-build-status-resource

A Concourse resource for interacting with Bitbucket servers
Other
19 stars 14 forks source link

bitbucket-build-status-resource

Docker Pulls Build Status

This is a fork of https://github.com/Karunamon/concourse-resource-bitbucket. The following forks have been merged in, too:

You can find a pre-built Docker image on DockerHub. If you come from one of the integrated forks, you can use the image with tag compatibility, which should work without you changing anything else.

Source Configuration

These items go in the source fields of the resource type. Bold items are required:

There are two supported drivers, with their own sets of properties for configuring them.

Bitbucket Cloud Driver

Authentication

One of the following two sets of properties must be specified:

Username and password
OAuth client id and secert
Creating an Access Token

You need to create an OAuth access token for your Bitbucket Cloud team/user account with the following permissions: Webhooks (r/w), Repositories (r)

Make sure to provide a callback URL (it's not needed at runtime but OAuth insists on it anyway). For example, you can use the URL of your Concourse instance. Otherwise you will see an error similar to the following:

Access token result: <Response [400]>{"error_description": "No callback uri defined for the OAuth client.", "error": "invalid_request"}
HTTP 401 Unauthorized - Are your bitbucket credentials correct?

Bitbucket Server Driver

check: Not supported

in: Not supported

out: Update the build status of a commit

Parameters

Example

A typical use case is to update the build status of a commit as it traverses your pipeline. The following example marks the commit as pending before unit tests start. Once unit tests finish, the build status is updated to either success or failure depending on how the task completes.


resource_types:
  - name: bitbucket-build-status
    type: docker-image
    source:
      repository: shyxormz/bitbucket-build-status-resource

resources:
  - name: testing-repo
    type: git
    source:
      uri: https://bitbucket.org/someuser/somerepo.git
      branch: master

  - name: build-status
    type: bitbucket-build-status
    source:
      client_id: cid
      client_secret: hemligt
      repository: someuser/somerepo

jobs:
  - name: unit-tests
    plan:
    - get: testing-repo
      trigger: true

    - put: build-status
      params:
        build_status: INPROGRESS
        repository: testing-repo

    - task: tests
      file: testing-repo/task.yml
      on_success:
        put: build-status
        params:
          build_status: SUCCESSFUL
          repository: testing-repo
      on_failure:
        put: build-status
        params:
          build_status: FAILED
          repository: testing-repo

In this example, notice that the repository parameter is set to the same name as the testing-repo resource. To reiterate: In your deployment, set the repository field to the directory name of the repository, or in other words, what you'd end up with if you ran a git/hg clone against the URI.

To install on all Concourse workers, update your deployment manifest properties to include a new groundcrew.resource_types entry...

properties:
  groundcrew:
    additional_resource_types:
      - image: "docker:///shyxormz/bitbucket-build-status-resource#latest"
        type: "bitbucket-build-status"

Pipeline-specific

To use on a single pipeline, update your pipeline to include a new resource_types entry...

resource_types:
  - name: bitbucket-build-status
    type: docker-image
    source:
      repository: shyxormz/bitbucket-build-status-resource
      tag: latest

Low hanging improvement fruit

This is a work in progress and there are multiple areas that could use some improvement. Any contribution is welcomed.

References

Thanks

License

Apache License v2.0