Skip to content

Tiny API that triggers Jenkins builds from GitHub Webhook

License

keenbytes/hooked-jenkins

Repository files navigation

hooked-jenkins

Tiny API that triggers Jenkins builds from GitHub Webhook

hooked-jenkins

⚠️ The project is really old and have not been maintained for years. It has been just slightly refreshed recently. However, some code snippets regarding Jenkins might be useful.

CLI

The following CLI commands are available:

hooked-jenkins start --config=PATH_TO_CONFIG_FILE

Building

Run the following command to compile binary:

go build -o hooked-jenkins

Configuration

Look at config-sample.json to see how the configuration file look like. It has changed since previous version a lot.

Now, all Jenkins details are now described in jenkins section. It contains 4 keys: user, token, base_url and endpoints. First two are obvious, base_url is prefix for your endpoints. endpoints is an array that contains objects as the following example:

{
  "id": "multibranch_pipeline_scan",
  "path": "/job/{{.repository}}_multibranch/build",
  "retry": {
    "delay": "10",
    "count": "5"
  },
  "success": {
    "http_status": "200"
  }
}

Keys of retry and success are optional. First one determines what is the maximum number application should retry posting to and endpoint and what should be the delay between retries. The success with http_status defined expected HTTP Status Code (eg. 200 or 201). If different then request is considered a failure (and will be retries if set to do so).

In path, any occurrence of {{.repository}} and {{.branch}} will be replaced with repository and branch names.

In above example, application will make a POST request to base_url+path.

Trigger conditions

You can now control what repositories and branches should trigger certain jenkins endpoints. In config-sample.json file, you can find the following block:

{
  "endpoint": "multibranch_pipeline_scan",
  "events": {
    "push": {
      "repositories": [
        { "name": "repo1", "branches": ["branch1", "branch2"] },
        { "name": "repo2" }
      ],
      "branches": [
        { "name": "branch3", "repositories": ["repo3"] },
        { "name": "branch4" }
      ]
    }
  }
}

Endpoint will be triggered only for push GitHub Webhook event and only when any entry in repositories or branches matches. As you can see you can define whole repo or repo with certain branches as well as the other way, user branch name with optional repository names.

In addition to that you can also use new exclude_repositories and exclude_branches blocks to determine what should be excluded.

Currently four events are available: push, pull_request, create and delete. When pull_request is used you can add actions blocks to determine which actions should trigger, eg.

    "pull_request": {
      "actions": ["opened", "reopened", "closed", "labeled", "unlabeled"]
    }

Forward payload

GitHub payload can be forwarded to another URL once successfully processed. To do this, just add the following block in your configuration (in the same level as triggers):

"forward": [
  { "url": "http://127.0.0.1:31111", "headers": true }
],

Running

Execute the binary, eg.

./hooked-jenkins start --config=PATH_TO_CONFIG_FILE

About

Tiny API that triggers Jenkins builds from GitHub Webhook

Topics

Resources

License

Stars

Watchers

Forks